Code a method to determine the activation block before any block has consensus

[0; 32] is a magic for no block has been set yet due to this being the first
key pair. If [0; 32] is the latest finalized block, the processor determines
an activation block based on timestamps.

This doesn't use an Option for ergonomic reasons.
This commit is contained in:
Luke Parker
2023-04-18 03:04:52 -04:00
parent 9da0eb69c7
commit 396e5322b4
8 changed files with 105 additions and 47 deletions

View File

@@ -119,10 +119,13 @@ async fn handle_key_gen<D: Db, Pro: Processor>(
.send(CoordinatorMessage::Substrate(
processor_messages::substrate::CoordinatorMessage::ConfirmKeyPair {
context: SubstrateContext {
serai_time: block.time().unwrap(),
coin_latest_finalized_block: serai
.get_latest_block_for_network(block.hash(), set.network)
.await?
.unwrap_or(BlockHash([0; 32])), // TODO: Have the processor override this
// The processor treats this as a magic value which will cause it to find a network
// block which has a time greater than or equal to the Serai time
.unwrap_or(BlockHash([0; 32])),
},
set,
key_pair,
@@ -206,7 +209,10 @@ async fn handle_batch_and_burns<D: Db, Pro: Processor>(
processor
.send(CoordinatorMessage::Substrate(
processor_messages::substrate::CoordinatorMessage::SubstrateBlock {
context: SubstrateContext { coin_latest_finalized_block },
context: SubstrateContext {
serai_time: block.time().unwrap(),
coin_latest_finalized_block,
},
key: get_coin_key(
serai,
// TODO2