From bde01bffbbd595947cd2354d7f932ca2bb47b12c Mon Sep 17 00:00:00 2001 From: Geoffrey Casper Date: Tue, 9 Apr 2024 15:11:14 -0400 Subject: [PATCH] block proposal: handle node being out of date (#31) --- src/services/new/witness/index.ts | 50 +++++++++---------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/src/services/new/witness/index.ts b/src/services/new/witness/index.ts index 8748da0..e2262fb 100644 --- a/src/services/new/witness/index.ts +++ b/src/services/new/witness/index.ts @@ -123,9 +123,7 @@ export class WitnessServiceV2 { valid_epoch?: number | null schedule?: Array } - //Precomputed list of blocks - _candidateBlocks: Record - candidateApprovalsDb: Collection + //VSC block headres ref blockHeaders: Collection delayMonitor: DelayMonitor; @@ -148,9 +146,6 @@ export class WitnessServiceV2 { valid_height: null, valid_epoch: null } - this._candidateBlocks = { - - } } @@ -812,32 +807,32 @@ export class WitnessServiceV2 { }) } - let cadBlockCtx: ReturnType | null = null + let updateCtx: ReturnType | null = null if (message?.traceInfo) { const block_height = this.self.chainBridge.streamParser.stream.lastBlock const slotHeight = (block_height - (block_height % networks[this.self.config.get('network.id')].roundLength)) //+ networks[this.self.config.get('network.id')].roundLength - cadBlockCtx = telemetry.continueTracedEvent(`computing candidate block ${slotHeight}`, message.traceInfo, { + updateCtx = telemetry.continueTracedEvent(`waiting for node to be up to date ${slotHeight}`, message.traceInfo, { block_height: slotHeight, latest_block: block_height, from: from?.toString(), }) } - let cadBlock = this._candidateBlocks[message.block_height] - if(!cadBlock) { - for(let attempts = 0; attempts < 12; attempts++) { - if(this._candidateBlocks[message.block_height]) { - cadBlock = this._candidateBlocks[message.block_height] - break; - } else { - await sleep(1_000) - } - } + const block_height = this.self.chainBridge.streamParser.stream.lastBlock + const slotHeight = (block_height - (block_height % networks[this.self.config.get('network.id')].roundLength)) //+ networks[this.self.config.get('network.id')].roundLength + + for(let attempts = 0; attempts < 12 && this.self.chainBridge.streamParser.lastParsed < slotHeight; attempts++) { + await sleep(1_000) } - cadBlockCtx?.finish() + updateCtx?.finish() + + if (this.self.chainBridge.streamParser.lastParsed < slotHeight) { + recvCtx?.finish() + return + } let verifyingCtx: ReturnType | null = null if (message?.traceInfo) { @@ -1075,23 +1070,6 @@ export class WitnessServiceV2 { verifyingCtx?.finish() recvCtx?.finish() } - - if(cadBlock) { - // delete cadBlock.block - // cadBlock.block = CID.parse(cadBlock.block.toString()) - // console.log('cadBlock.signRaw', cadBlock, (await encodePayload(cadBlock)).cid, await this.self.ipfs.block.put(IPLDDag.util.serialize(cadBlock), { - // format: 'dag-cbor' - // }), await this.self.ipfs.dag.put(cadBlock), await this.self.ipfs.dag.put({ - // testLink: CID.parse(cadBlock.block.toString()) - // })) - - - } - // const cid = CID.parse(message.hash) - // const signData = await this.self.consensusKey.signRaw(cid.bytes) - // console.log(signData) - - // drain.push(signData) } async init() {