Skip to content

Proposer to propose multiple L2 blocks at once #553

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 16 commits into from
Mar 14, 2022

Conversation

daveroga
Copy link
Contributor

@daveroga daveroga commented Mar 1, 2022

Feature #478

Feature

Once the current proposer changes, the new current proposer can submit multiple blocks at once.

  • If there are not enough unprocessed transactions for more than 1 block: it is similar to proposing 1 block at a time -> for each L2 block proposal, it will have to wait for prior events in the queue to be processed with their 12 confirmation wait included.
  • If there are too many unprocessed transactions: an upper limit for maximum number of L2 blocks to propose is required such that the proposer does not lose gas on all the L2 blocks that did not make it to L1 when they were the current proposer. MAX_L2_BLOCKS_TO_PROPOSE = Number of L1 blocks a proposer gets * the number of L2 blocks can fit in each L1. This assumes that L1 blocks are completely filled with NF's L2 block proposed transactions, this might need to be corrected by a factor

Actions

conditionalMakeBlock to create numberOfUnprocessedTransactions / TRANSACTIONS_PER_BLOCK blocks instead of just 1. This should allow us to build multiple blocks before having to process the events with their 12 confirmation wait in 0th queue.

  • Remove async from Block.build and pass the parameters needed instead.
  • makeBlock to return list of blocks and transactions per block instead of single block.
  • ws.send 'block' will send list of unsigned propose block transactions so that the proposer can send the list of unsigned tx to the state contract with proposeBlock.

Test

Created a test for this functionality. A user will create some deposits without a proposer and then a proposer will register and start to get all pending L2 blocks proposed txs to be proposed at once.

  • Start Nightfall with ./start-nightfall -g -s -d
  • Run the test npm run test-e2e-protocol that includes proposer should propose multiple L2 blocks after deposits test.

@daverogadaveroga force-pushed the daveroga/proposer-multiple-blocks branch from 5cc86b4 to 710f593 Compare March 2, 2022 14:01
@daverogadaveroga force-pushed the daveroga/proposer-multiple-blocks branch from cd3054a to 39c6925 Compare March 2, 2022 23:15
@daverogadaveroga requested a review from IlyasRidhuan March 3, 2022 01:36
@daverogadaveroga force-pushed the daveroga/proposer-multiple-blocks branch from fb920f2 to 4a7c938 Compare March 4, 2022 09:38
@daverogadaveroga linked an issue Mar 7, 2022that may be closed by this pull request
@daverogadaveroga self-assigned this Mar 7, 2022
Copy link
Contributor

@signorecello signorecello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@daverogadaveroga force-pushed the daveroga/proposer-multiple-blocks branch from 44a5e7f to 8959da1 Compare March 9, 2022 10:24
@daverogadaveroga force-pushed the daveroga/proposer-multiple-blocks branch from c3c1c62 to 1ac8955 Compare March 10, 2022 20:18
@daveroga
Copy link
Contributor Author

daveroga commented Mar 11, 2022

During the tests I checked the message sent by logger.debug('Found ${txDataToSignList.length} blocks to process'); but it's true that I have to pass some check directly to the test and check it there. I've updated the test sending another parameter with the number of blocks proposed in the 'gasCost' event.

expect(blocksReceivedToPropose).to.be.equal(Math.floor(totalDeposits / txPerBlock));

@daverogadaveroga requested a review from druiz0992 March 11, 2022 10:24
@ChaitanyaKonda
Copy link
Contributor

During the tests I checked the message sent by logger.debug('Found ${txDataToSignList.length} blocks to process'); but it's true that I have to pass some check directly to the test and check it there. I've updated the test sending another parameter with the number of blocks proposed in the 'gasCost' event.

expect(blocksReceivedToPropose).to.be.equal(Math.floor(totalDeposits / txPerBlock));

How is blocksReceivedToPropose defined ?

@daveroga
Copy link
Contributor Author

daveroga commented Mar 11, 2022

It's the txDataToSignList.length. Length of the list of txDataToSign. Data to sign of blocks to propose that the proposer receive with the data of type 'block' from the optimist.
Before the update the proposer received txtDataToSign and now receives a list of this txtDataToSign. It's the list we use the reduce pattern to submit the signed transaction for every block proposed.

txDataToSignList.reduce((seq, txDataToSign) => {
          return seq.then(() => {
            return this.submitTransaction(
              txDataToSign,
              this.stateContractAddress,
              this.BLOCK_STAKE,
            ).then(res => newGasBlockEmitter.emit('gascost', res.gasUsed, txDataToSignList.length));
          });
        }, Promise.resolve());

@ChaitanyaKondaChaitanyaKonda added the DNMDo not mergelabel Mar 14, 2022
@daverogadaveroga added One more approval neededOne reviewer has approved this PR but another is neededand removed DNMDo not mergelabels Mar 14, 2022
@ChaitanyaKondaChaitanyaKonda merged commit df9604e into master Mar 14, 2022
@ChaitanyaKondaChaitanyaKonda deleted the daveroga/proposer-multiple-blocks branch March 14, 2022 18:23
Sign up for free to join this conversation on . Already have an account? Sign in to comment
Labels
One more approval neededOne reviewer has approved this PR but another is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposer to propose multiple L2 blocks at once
5 participants