Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ let config: Config = {
GiveUpAge: 20 * 60, // 20 minutes
lastFailedBucketDuration: 5 * 60 * 1000, // 5 minutes
RadixDepth: 2, // 2 nibbles (1 hex char)
allowCheckpointUpdates: false,
allowCheckpointStorage: false,
allowCheckpointUpdates: true,
allowCheckpointStorage: true,
},
batchSize: 100,
updateInterval: 60 * 1000, // 1 minute in milliseconds in milliseconds
Expand Down
5 changes: 5 additions & 0 deletions src/Data/Collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ export const storeReceiptData = async (
if (!txId || !timestamp) {
continue
}
if (senderInfo === 'checkpoint') {
Logger.mainLogger.error(
`[CHECKPOINT_RECEIPT_RECEIVED] receiptId=${txId} cycle=${receipt.cycle} timestamp=${timestamp}`
)
}
if (
checkpoint &&
((processedReceiptsMap.has(txId) && processedReceiptsMap.get(txId) === timestamp) ||
Expand Down
13 changes: 7 additions & 6 deletions src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,16 +998,18 @@ export async function getConsensusRadius(): Promise<number> {
}
if (nodesPerConsensusGroup === nodesPerConsensusGroupFromConfig && nodesPerEdge === nodesPerEdgeFromConfig)
return currentConsensusRadius
nodesPerConsensusGroup = nodesPerConsensusGroupFromConfig
nodesPerEdge = nodesPerEdgeFromConfig
let newNodesPerConsensusGroup = nodesPerConsensusGroupFromConfig
// Upgrading consensus size to an odd number
if (nodesPerConsensusGroup % 2 === 0) nodesPerConsensusGroup++
const consensusRadius = Math.floor((nodesPerConsensusGroup - 1) / 2)
if (newNodesPerConsensusGroup % 2 === 0) newNodesPerConsensusGroup++
const consensusRadius = Math.floor((newNodesPerConsensusGroup - 1) / 2)
// Validation: Ensure consensusRadius is a number and greater than zero
if (typeof consensusRadius !== 'number' || isNaN(consensusRadius) || consensusRadius <= 0) {
Logger.mainLogger.error('Invalid consensusRadius:', consensusRadius)
return currentConsensusRadius // Return the existing currentConsensusRadius in case of invalid consensusRadius
}
nodesPerConsensusGroup = newNodesPerConsensusGroup
nodesPerEdge = nodesPerEdgeFromConfig
currentConsensusRadius = consensusRadius
Logger.mainLogger.debug(
'consensusRadius',
consensusRadius,
Expand Down Expand Up @@ -1056,7 +1058,6 @@ export async function createNodesGroupByConsensusRadius(): Promise<void> {
Logger.mainLogger.error('Consensus radius is 0, unable to create nodes group.')
return // Early return to prevent further execution
}
currentConsensusRadius = consensusRadius
const activeList = [...NodeList.activeListByIdSorted]
if (config.VERBOSE) Logger.mainLogger.debug('activeList', activeList.length, activeList)
let totalNumberOfNodesToSubscribe = Math.ceil(activeList.length / consensusRadius)
Expand Down Expand Up @@ -1788,7 +1789,7 @@ export async function syncCyclesAndNodeListV2(
Logger.mainLogger.debug('cycleToSyncTo', cycleToSyncTo)
Logger.mainLogger.debug(`Syncing till cycle ${cycleToSyncTo.counter}...`)

currentConsensusRadius = await getConsensusRadius()
await getConsensusRadius()
await processCycles([cycleToSyncTo])

// Download old cycle Records
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoint/CheckpointData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ export class CheckpointBucket<T> {
radixEntries: Array.from(this.radixEntries.entries()),
peerDigests: Array.from(this.peerRadixDigests.entries()),
}
const filename = `${config.failedBucketsDir}/failed-bucket-${this.checkpointType}-${this.bucketID}-${this.startTime}.json`
const filename = `${config.failedBucketsDir}/${config.ARCHIVER_IP}_${config.ARCHIVER_PORT}/failed-bucket-${this.checkpointType}-${this.bucketID}-${this.startTime}.json`
if (config.VERBOSE) {
Logger.mainLogger.debug(`Writing bucket id ${this.bucketID} data to file ${filename}`)
}
Expand Down
5 changes: 3 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async function start(): Promise<void> {
// Initialize storage and checkpoints
if (config.experimentalSnapshot) {
await dbstore.initializeDB(config)
getLastUpdatedCycle()
} else {
await Storage.initStorage(config)
}
Expand Down Expand Up @@ -246,8 +247,8 @@ async function start(): Promise<void> {
scheduleMultiSigKeysSyncFromNetConfig()
}, 60 * 1000) // Start after 60 seconds

// Create the failed buckets directory
createDirectories(config.failedBucketsDir)
// Create the failed buckets directory for this archiver instance
createDirectories(`${config.failedBucketsDir}/${config.ARCHIVER_IP}_${config.ARCHIVER_PORT}`)

// Initialize checkpoint V2 system if enabled and checkpoint updates and storage are allowed
if (config.checkpoint.bucketConfig.allowCheckpointUpdates) {
Expand Down
2 changes: 1 addition & 1 deletion src/statistics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ class Ring {
average(): number {
let sum = 0
let total = 0
console.log('elements', this.elements)
// console.log('elements', this.elements)
for (const element of this.elements) {
if (_exists(element)) {
sum += Number(element)
Expand Down
15 changes: 10 additions & 5 deletions src/utils/cycleTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@ interface CycleTrackerData {
lastUpdatedTimestamp: number
}

const CYCLE_TRACKER_FILE = path.join(process.cwd(), 'cycle-tracker.json')
function getCycleTrackerFile(): string {
return path.join(config.ARCHIVER_DB, 'cycle-tracker.json')
}

/**
* Gets the last updated cycle from the tracker file
* @returns The last updated cycle number, or 0 if not found
*/
export function getLastUpdatedCycle(): number {
const cycleTrackerFile = getCycleTrackerFile()

try {
let data: string

try {
data = fs.readFileSync(CYCLE_TRACKER_FILE, 'utf8')
data = fs.readFileSync(cycleTrackerFile, 'utf8')
} catch (error) {
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
const trackerData: CycleTrackerData = {
Expand All @@ -30,16 +34,17 @@ export function getLastUpdatedCycle(): number {

try {
const fd = fs.openSync(
CYCLE_TRACKER_FILE,
cycleTrackerFile,
fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY,
0o600
)
fs.writeFileSync(fd, JSON.stringify(trackerData, null, 2), 'utf8')
fs.closeSync(fd)
Logger.mainLogger.debug(`Created cycle tracker file at ${cycleTrackerFile}`)
return 0
} catch (createError) {
if ((createError as NodeJS.ErrnoException).code === 'EEXIST') {
data = fs.readFileSync(CYCLE_TRACKER_FILE, 'utf8')
data = fs.readFileSync(cycleTrackerFile, 'utf8')
} else {
throw createError
}
Expand Down Expand Up @@ -70,7 +75,7 @@ export function updateLastUpdatedCycle(cycle: number): void {
lastUpdatedTimestamp: Date.now(),
}

fs.writeFileSync(CYCLE_TRACKER_FILE, JSON.stringify(trackerData, null, 2), 'utf8')
fs.writeFileSync(getCycleTrackerFile(), JSON.stringify(trackerData, null, 2), 'utf8')
Logger.mainLogger.debug(`Updated cycle tracker to cycle ${cycle}`)
} catch (error) {
Logger.mainLogger.error('Error updating cycle tracker file:', error)
Expand Down
3 changes: 2 additions & 1 deletion test/unit/src/utils/cycleTracker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jest.mock('../../../../src/dbstore/index', () => ({}))
jest.mock('../../../../src/dbstore/checkpointStatus')
jest.mock('../../../../src/Config', () => ({
config: {
ARCHIVER_DB: '/tmp/archiver-db',
checkpoint: {
bucketConfig: {
GiveUpAge: 20,
Expand Down Expand Up @@ -42,7 +43,7 @@ const mockGetCheckpointStatusesByUnifiedStatus = getCheckpointStatusesByUnifiedS
>

describe('cycleTracker', () => {
const CYCLE_TRACKER_FILE = path.join(process.cwd(), 'cycle-tracker.json')
const CYCLE_TRACKER_FILE = path.join(config.ARCHIVER_DB, 'cycle-tracker.json')
const mockDate = new Date('2024-01-15T10:30:00Z').getTime()

beforeEach(() => {
Expand Down
Loading