From fbf6542aa0613003b9945cb4e2c67c25066b6cbe Mon Sep 17 00:00:00 2001 From: Alex Gherghisan Date: Tue, 16 Jan 2024 14:32:32 +0000 Subject: [PATCH] refactor: invert if check --- .../src/sequencer/sequencer.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/yarn-project/sequencer-client/src/sequencer/sequencer.ts b/yarn-project/sequencer-client/src/sequencer/sequencer.ts index e88d49deaf2..f23c8c9a9df 100644 --- a/yarn-project/sequencer-client/src/sequencer/sequencer.ts +++ b/yarn-project/sequencer-client/src/sequencer/sequencer.ts @@ -237,16 +237,24 @@ export class Sequencer { this.state = SequencerState.PUBLISHING_CONTRACT_DATA; const newContracts = validTxs.flatMap(tx => tx.newContracts).filter(cd => !cd.isEmpty()); - if (newContracts.length > 0) { - const blockHash = block.getCalldataHash(); - this.log.info(`Publishing ${newContracts.length} contracts in block hash ${blockHash.toString('hex')}`); - - const publishedContractData = await this.publisher.processNewContractData(block.number, blockHash, newContracts); - if (publishedContractData) { - this.log(`Successfully published new contract data for block ${block.number}`); - } else if (!publishedContractData && newContracts.length) { - this.log(`Failed to publish new contract data for block ${block.number}`); - } + if (newContracts.length === 0) { + this.log.debug(`No new contracts to publish in block ${block.number}`); + return; + } + + const blockCalldataHash = block.getCalldataHash(); + this.log.info(`Publishing ${newContracts.length} contracts in block ${block.number}`); + + const publishedContractData = await this.publisher.processNewContractData( + block.number, + blockCalldataHash, + newContracts, + ); + + if (publishedContractData) { + this.log(`Successfully published new contract data for block ${block.number}`); + } else if (!publishedContractData && newContracts.length) { + this.log(`Failed to publish new contract data for block ${block.number}`); } }