Baker: do not wait for block application before attesting
Context
This MR makes the following changes to the baker:
- The round phases are now ordered as follows:
Idle -> Await_preattestations -> Await_attestations -> Await_application
- Attestations are sent immediately after prequorum has been detected, without waiting for block application
- Block application is required before baking at next block
Potential issues (need to be addressed in this same MR)
- Receiving a new head proposal at the same level, after observing a quorum but before block has been applied, might cause to update the latest proposal. This might lead to increasing the number of chain reorganisations.
- potential solution: Ignore new proposals at higher rounds when
Awaiting_application
, only handle branch switches
- potential solution: Ignore new proposals at higher rounds when
Closes #6494 (closed)
Tasks:
-
Do not wait for block application before sending attestation -
Ensure that block has been applied before proposing at next level
Manually testing the MR
Testing the baker in test_scenario.ml
New scenario t4 added, which tests for:
- nodes sending attestations before a block is applied
- A block that has proposing rights and has observed quorum at a previous level will not propose, if the block at the previous level was not applied. Tested the scenario also on Nairobi and Oxford
dune exec src/proto_alpha/lib_delegate/test/main.exe -- --file test_scenario.ml --title 'mockup_baking: alpha: scenario t4 (alpha: scenario t4)' --verbose
Testing quorum received before application in sandbox:
Requires the following patch to be applied. This will delay block application in the baker by 5 seconds, and set the block time of the sandbox to 10 seconds.
diff --git a/src/proto_alpha/lib_delegate/node_rpc.ml b/src/proto_alpha/lib_delegate/node_rpc.ml
index fef2094582..3c8873d690 100644
--- a/src/proto_alpha/lib_delegate/node_rpc.ml
+++ b/src/proto_alpha/lib_delegate/node_rpc.ml
@@ -326,6 +326,7 @@ let monitor_heads cctxt ~chain ?cache () =
let map (block_hash, block_header) =
Profiler.reset_block_section block_hash ;
Profiler.record_s "received new head" @@ fun () ->
+ let*! () = Lwt_unix.sleep 5. in
let*! map_result = proposal cctxt ?cache ~chain block_hash block_header in
match map_result with
| Ok proposal -> Lwt.return_some proposal
diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml
index 9aef53823b..8f4dd71ab7 100644
--- a/src/proto_alpha/lib_parameters/default_parameters.ml
+++ b/src/proto_alpha/lib_parameters/default_parameters.ml
@@ -295,7 +295,7 @@ let derive_cryptobox_parameters ~redundancy_factor ~mainnet_constants_divider =
let constants_sandbox =
let consensus_committee_size = 256 in
- let block_time = 1 in
+ let block_time = 10 in
let Constants.Generated.{consensus_threshold = _; issuance_weights} =
Constants.Generated.generate ~consensus_committee_size
in
- Compile the binaries
make
- Start a node in a sandbox with a baker
# shell1
./src/bin_node/octez-sandboxed-node.sh 1 --connections 1
# shell2
eval `./src/bin_client/octez-init-sandboxed-client.sh 1`
octez-activate-alpha
TEZOS_LOG="*->debug" octez-baker-alpha run remotely
relevant output from the baker:
Oct 27 15:25:46.029: received new proposal BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA at
Oct 27 15:25:46.029: level 5, round 0
Oct 27 15:25:46.029: received new head with level increasing
Oct 27 15:25:46.034: attempting to preattest proposal
Oct 27 15:25:46.034: BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA
Oct 27 15:25:46.034: signing preattestation for bootstrap1 (tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx)
Oct 27 15:25:46.034: end of stream
Oct 27 15:25:46.037: signing preattestation for bootstrap4 (tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv)
Oct 27 15:25:46.039: signing preattestation for bootstrap5 (tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv)
Oct 27 15:25:46.041: signing preattestation for bootstrap3 (tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU)
Oct 27 15:25:46.042: starting new monitoring
Oct 27 15:25:46.044: signing preattestation for bootstrap2 (tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN)
Oct 27 15:25:46.050: injected preattestation opYQvM9cTAFrApekYwfhyEUZwQi3GFLdQE2JjDfBZkAQWf1znnL
Oct 27 15:25:46.050: for bootstrap3 (tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU) for level 5, round 0
Oct 27 15:25:46.050: injected preattestation ooGUuv993eR5o2AmaXh27qkBQfi3j31qFMKKN6aHx7kGhYsxo58
Oct 27 15:25:46.050: for bootstrap4 (tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv) for level 5, round 0
Oct 27 15:25:46.050: injected preattestation op2trc9hCACGHrqL2rur2QhKJ7UTqD9jo1en38shZREgnGD7M6A
Oct 27 15:25:46.050: for bootstrap2 (tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN) for level 5, round 0
Oct 27 15:25:46.050: injected preattestation onhxWBzw4KccdTktESE6fxAscQqH6RMLDGrK9VVGMrdovJzw37P
Oct 27 15:25:46.050: for bootstrap1 (tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx) for level 5, round 0
Oct 27 15:25:46.050: injected preattestation ooRd3VzsxbjUqqQ6g525DMTNLFZghnkBn5map2qjQavbwmsNTd2
Oct 27 15:25:46.050: for bootstrap5 (tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv) for level 5, round 0
Oct 27 15:25:46.051: prequorum reached (voting power: 103, 2 preattestations)
Oct 27 15:25:46.051: waiting 9.949s until end of round 0 at 2023-10-27T14:25:56-00:00
Oct 27 15:25:46.051: automaton step: current phase awaiting preattestations, event
Oct 27 15:25:46.051: prequorum reached with 2 preattestations for BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA at round 0
Oct 27 15:25:46.052: signing attestation for bootstrap1 (tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx)
Oct 27 15:25:46.054: signing attestation for bootstrap4 (tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv)
Oct 27 15:25:46.055: signing attestation for bootstrap5 (tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv)
Oct 27 15:25:46.057: signing attestation for bootstrap3 (tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU)
Oct 27 15:25:46.059: signing attestation for bootstrap2 (tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN)
Oct 27 15:25:46.063: injected attestation op3qT2C8YWAbPxsz4eewKmyL1tUnzvA2ZeAaFBzmzZNwAFPDPjJ for
Oct 27 15:25:46.063: bootstrap2 (tz1gjaF81ZRRvdzjobyfVNsAeSC6PScjfQwN) for level 5, round 0
Oct 27 15:25:46.063: injected attestation opMf6dEFqVy4QFZEtZeYsrMtVFpfZaQbU55tUDnpCAYPaRmVTx5 for
Oct 27 15:25:46.063: bootstrap3 (tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU) for level 5, round 0
Oct 27 15:25:46.063: injected attestation op1LHwx3uwYa7ig3PxoRVnjMvFkK3CYnyMUpuGaREbraUPn8Kos for
Oct 27 15:25:46.063: bootstrap1 (tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx) for level 5, round 0
Oct 27 15:25:46.063: injected attestation opJ3Azm9AJpdA9cSbsBCyNkPQniN1pQ8pq3U4i5XajduwvStaLJ for
Oct 27 15:25:46.063: bootstrap4 (tz1b7tUupMgCNw2cCLpKTkSD1NZzB5TkP2sv) for level 5, round 0
Oct 27 15:25:46.063: injected attestation ooDpwJRqTGhLEyQ94Pqo462bR2kje5kVwK6Xw9BJS7iDJXPyzbN for
Oct 27 15:25:46.063: bootstrap5 (tz1ddb9NMYHZi5UzPdzTZMYQQZoMub195zgv) for level 5, round 0
Oct 27 15:25:46.063: quorum reached (voting power: 102, 2 attestations)
Oct 27 15:25:46.063: waiting 9.937s until end of round 0 at 2023-10-27T14:25:56-00:00
Oct 27 15:25:46.064: automaton step: current phase awaiting attestations, event
Oct 27 15:25:46.064: quorum reached with 2 attestations for BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA at round 0
Oct 27 15:25:46.064: waiting 9.936s until end of round 0 at 2023-10-27T14:25:56-00:00
Oct 27 15:25:51.039: automaton step: current phase awaiting application, event
Oct 27 15:25:51.039: new head proposal received: Block:
Oct 27 15:25:51.039: hash: BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA
Oct 27 15:25:51.039: payload_hash: vh32feJ9uGxUJ
Oct 27 15:25:51.039: level: 5
Oct 27 15:25:51.039: round: 0
Oct 27 15:25:51.039: prequorum: none
Oct 27 15:25:51.039: quorum: 5 attestations
Oct 27 15:25:51.039: dal_attestations: 0
Oct 27 15:25:51.039: payload: [votes: 0, anonymous: 0, managers: 0]
Oct 27 15:25:51.039: payload round: 0
Oct 27 15:25:51.041: received the expected application notice for
Oct 27 15:25:51.041: BLmQBJgoBwax8mm7d4CnnNbWHqh1opvm3c2qMNtDgx1QbCSPuLA
Oct 27 15:25:51.043: found an elected block at level 5, round 0... checking baking rights
Oct 27 15:25:51.047: next potential slot for level 6 is at round 0 at 2023-10-27T14:25:56-00:00
Testing block application before quorum
- Requires the following patch:
diff --git a/src/proto_alpha/lib_delegate/operation_worker.ml b/src/proto_alpha/lib_delegate/operation_worker.ml
index 4d2426411d..16cc672b9c 100644
--- a/src/proto_alpha/lib_delegate/operation_worker.ml
+++ b/src/proto_alpha/lib_delegate/operation_worker.ml
@@ -435,6 +435,7 @@ let update_monitoring ?(should_lock = true) state ops =
( proposal_watched.current_voting_power,
proposal_watched.attestations_count ))
in
+ let* () = Lwt_unix.sleep 5. in
state.qc_event_stream.push
(Some
(Quorum_reached
diff --git a/src/proto_alpha/lib_parameters/default_parameters.ml b/src/proto_alpha/lib_parameters/default_parameters.ml
index 9aef53823b..8f4dd71ab7 100644
--- a/src/proto_alpha/lib_parameters/default_parameters.ml
+++ b/src/proto_alpha/lib_parameters/default_parameters.ml
@@ -295,7 +295,7 @@ let derive_cryptobox_parameters ~redundancy_factor ~mainnet_constants_divider =
let constants_sandbox =
let consensus_committee_size = 256 in
- let block_time = 1 in
+ let block_time = 10 in
let Constants.Generated.{consensus_threshold = _; issuance_weights} =
Constants.Generated.generate ~consensus_committee_size
in
TODO: finish updating testing report
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rst
for the protocol and the environment,CHANGES.rst
at the root of the repository for everything else). -
Select suitable reviewers using the Reviewers
field below. -
Select as Assignee
the next person who should take action on that MR
Edited by Andrea Cerone