Skip to content

Commit

Permalink
Merge branch 'origin/tomas/persist-epoch-update-delay' (#1455)
Browse files Browse the repository at this point in the history
* origin/tomas/persist-epoch-update-delay:
  changelog: #1455
  storage: persist `update_epoch_blocks_delay`
  • Loading branch information
Fraccaman committed Jun 2, 2023
2 parents af6d79b + 62dd559 commit a458b55
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Persists a newly added storage field for epoch update blocks delay to be
available after node restart when not `None` which may break consensus.
([\#1455](https://github.com/anoma/namada/pull/1455))
37 changes: 36 additions & 1 deletion apps/src/lib/node/ledger/storage/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,19 @@ impl DB for RocksDB {
return Ok(None);
}
};
let update_epoch_blocks_delay: Option<u32> = match self
.0
.get_cf(state_cf, "update_epoch_blocks_delay")
.map_err(|e| Error::DBError(e.into_string()))?
{
Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?,
None => {
tracing::error!(
"Couldn't load epoch update block delay from the DB"
);
return Ok(None);
}
};
let tx_queue: TxQueue = match self
.0
.get_cf(state_cf, "tx_queue")
Expand Down Expand Up @@ -636,6 +649,7 @@ impl DB for RocksDB {
results,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
address_gen,
tx_queue,
}))
Expand All @@ -660,10 +674,11 @@ impl DB for RocksDB {
height,
epoch,
pred_epochs,
results,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
address_gen,
results,
tx_queue,
}: BlockStateWrite = state;

Expand Down Expand Up @@ -704,6 +719,24 @@ impl DB for RocksDB {
"next_epoch_min_start_time",
types::encode(&next_epoch_min_start_time),
);
if let Some(current_value) = self
.0
.get_cf(state_cf, "update_epoch_blocks_delay")
.map_err(|e| Error::DBError(e.into_string()))?
{
// Write the predecessor value for rollback
batch.0.put_cf(
state_cf,
"pred/update_epoch_blocks_delay",
current_value,
);
}
batch.0.put_cf(
state_cf,
"update_epoch_blocks_delay",
types::encode(&update_epoch_blocks_delay),
);

// Tx queue
if let Some(pred_tx_queue) = self
.0
Expand Down Expand Up @@ -1412,6 +1445,7 @@ mod test {
let height = BlockHeight::default();
let next_epoch_min_start_height = BlockHeight::default();
let next_epoch_min_start_time = DateTimeUtc::now();
let update_epoch_blocks_delay = None;
let address_gen = EstablishedAddressGen::new("whatever");
let tx_queue = TxQueue::default();
let results = BlockResults::default();
Expand All @@ -1425,6 +1459,7 @@ mod test {
pred_epochs: &pred_epochs,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
address_gen: &address_gen,
tx_queue: &tx_queue,
};
Expand Down
13 changes: 13 additions & 0 deletions core/src/ledger/storage/mockdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ impl DB for MockDB {
}
None => return Ok(None),
};
let update_epoch_blocks_delay: Option<u32> =
match self.0.borrow().get("update_epoch_blocks_delay") {
Some(bytes) => {
types::decode(bytes).map_err(Error::CodingError)?
}
None => return Ok(None),
};
#[cfg(feature = "ferveo-tpke")]
let tx_queue: TxQueue = match self.0.borrow().get("tx_queue") {
Some(bytes) => types::decode(bytes).map_err(Error::CodingError)?,
Expand Down Expand Up @@ -160,6 +167,7 @@ impl DB for MockDB {
pred_epochs,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
address_gen,
results,
#[cfg(feature = "ferveo-tpke")]
Expand Down Expand Up @@ -188,6 +196,7 @@ impl DB for MockDB {
pred_epochs,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
address_gen,
results,
#[cfg(feature = "ferveo-tpke")]
Expand All @@ -203,6 +212,10 @@ impl DB for MockDB {
"next_epoch_min_start_time".into(),
types::encode(&next_epoch_min_start_time),
);
self.0.borrow_mut().insert(
"update_epoch_blocks_delay".into(),
types::encode(&update_epoch_blocks_delay),
);
#[cfg(feature = "ferveo-tpke")]
{
self.0
Expand Down
7 changes: 7 additions & 0 deletions core/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ pub struct BlockStateRead {
pub next_epoch_min_start_height: BlockHeight,
/// Minimum block time at which the next epoch may start
pub next_epoch_min_start_time: DateTimeUtc,
/// Update epoch delay
pub update_epoch_blocks_delay: Option<u32>,
/// Established address generator
pub address_gen: EstablishedAddressGen,
/// Results of applying transactions
Expand Down Expand Up @@ -195,6 +197,8 @@ pub struct BlockStateWrite<'a> {
pub next_epoch_min_start_height: BlockHeight,
/// Minimum block time at which the next epoch may start
pub next_epoch_min_start_time: DateTimeUtc,
/// Update epoch delay
pub update_epoch_blocks_delay: Option<u32>,
/// Established address generator
pub address_gen: &'a EstablishedAddressGen,
/// Results of applying transactions
Expand Down Expand Up @@ -390,6 +394,7 @@ where
pred_epochs,
next_epoch_min_start_height,
next_epoch_min_start_time,
update_epoch_blocks_delay,
results,
address_gen,
#[cfg(feature = "ferveo-tpke")]
Expand All @@ -405,6 +410,7 @@ where
self.last_epoch = epoch;
self.next_epoch_min_start_height = next_epoch_min_start_height;
self.next_epoch_min_start_time = next_epoch_min_start_time;
self.update_epoch_blocks_delay = update_epoch_blocks_delay;
self.address_gen = address_gen;
// Rebuild Merkle tree
self.block.tree = MerkleTree::new(merkle_tree_stores)
Expand Down Expand Up @@ -462,6 +468,7 @@ where
pred_epochs: &self.block.pred_epochs,
next_epoch_min_start_height: self.next_epoch_min_start_height,
next_epoch_min_start_time: self.next_epoch_min_start_time,
update_epoch_blocks_delay: self.update_epoch_blocks_delay,
address_gen: &self.address_gen,
#[cfg(feature = "ferveo-tpke")]
tx_queue: &self.tx_queue,
Expand Down
37 changes: 19 additions & 18 deletions wasm/checksums.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"tx_bond.wasm": "tx_bond.360a16af664842abe4ca7633e3d16e9207afcaff01510104a0035883516b56c4.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.844c133aea4674dc4b80e2c7a8c00b7ced4cee2d421493b07c565fbcd6401866.wasm",
"tx_ibc.wasm": "tx_ibc.a7e6d830c9f3e90ce8fa2d836bc13cf0509ca62109b4bbf983fff6048970fab7.wasm",
"tx_init_account.wasm": "tx_init_account.01e37106bb29c4c2d23af6ccb4924d84697fab21e92c3382eec1113a59e0648f.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.f4068611a46ab6533387f0143c5a31277062c2bf2e0b3ae2132b49d49c4bd2ef.wasm",
"tx_init_validator.wasm": "tx_init_validator.9a6e3d55eb6865550db9b06397432f27b5e8877b005a38d5c73071a34f47ec7f.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.db2e73ea54b3ded2795736ccb4a07e224f1e275c8343d68e8cefec1b28cdbd82.wasm",
"tx_transfer.wasm": "tx_transfer.a1b1af7c933a032c4fe4b5e8e30e8b6f67c273a4cc5bd380dc491feb3c9240f6.wasm",
"tx_unbond.wasm": "tx_unbond.eb7799087e4329dd34264b90d25017d408ed644ea8a974708d166a325b3333b9.wasm",
"tx_update_vp.wasm": "tx_update_vp.cd2aac94210c48bc4209214b3eb41e1ecec0753ca7dda272e5e72b024cbed9c1.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.75eaa57dd78ee1d179d3073ce0b6e39b6fc3983908bba7f8c7538672c333c695.wasm",
"tx_withdraw.wasm": "tx_withdraw.338430de243e6ee84d5b451f4b7f704d5c9234d6459d7344256e5bf064a97e17.wasm",
"vp_implicit.wasm": "vp_implicit.1a97aacb048ab2e6a1dd5c895db669af39850b8a7f77758c0e5a2595aa19df06.wasm",
"vp_masp.wasm": "vp_masp.47b962c30f9da3f2775103f10d1b4cd51c48365529ee5ca5567b9e863989dfda.wasm",
"vp_testnet_faucet.wasm": "vp_testnet_faucet.92b8cb6f853d849839c774d0fbe44a3f677694a5444b06cf74f9b357003ccb29.wasm",
"vp_token.wasm": "vp_token.1e2c8ba9a27ce584c6599c6c2cf4b9004ec2a008d9f60ad81ca7f503af7847b8.wasm",
"vp_user.wasm": "vp_user.cd5333ba8ab5ad26c53b5e3c8c4ca4ec7ec38557557f5d7413e7a65dc85d6e2a.wasm",
"vp_validator.wasm": "vp_validator.cf019daf988ba6900a5aa05f7a09e006435e2909cbd1777311731b17369f4f6a.wasm"
"tx_bond.wasm": "tx_bond.e72837fe265346308458d4e5f2399633bcf553ea13679434ea54fa578c13a912.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.4006b3a3251970b40290e1c898809ac914f9450c1f82e3026fdadca96eb42810.wasm",
"tx_ibc.wasm": "tx_ibc.012d3f1da7532f3ff92bb56499c349ea3e5b6abaf4bdb7b8faa0177bf7ea2b93.wasm",
"tx_init_account.wasm": "tx_init_account.6359caa0d6fda1d896b84a881351c6827aca66240988b438697c966dec231be2.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.339f4454df0be8ae670c5df84645c7b156f478726dc1e964a93cea4f8b6a4651.wasm",
"tx_init_validator.wasm": "tx_init_validator.a45ef2fc87cf2760107cd682a34772207da3ee96de778e5e83f22256df99ff7d.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.b7541013221fedb42d9bdd4be6e972deac147b8c930b03db282f0b7811198554.wasm",
"tx_transfer.wasm": "tx_transfer.8b6fb1f418fea7d8909ed45160b9614f6ff50421fd766ce7ac9c1767af848aa7.wasm",
"tx_unbond.wasm": "tx_unbond.7f4c904a13ec2d4716457290a5af1f2f8853ccb817276583fccb33a63add07bd.wasm",
"tx_unjail_validator.wasm": "tx_unjail_validator.aadc50cd196eb818dd3f743c1be3f2973e9fdcbe9f1d7334dedbfee38f822ccc.wasm",
"tx_update_vp.wasm": "tx_update_vp.e5d25854a23186925caa2169869b1505e29132b8a8b396e911379d53ce5cf418.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.22b3358af6611d1786f6d49ccbf0757e3065a43fb37e8df0055f2173c8e14653.wasm",
"tx_withdraw.wasm": "tx_withdraw.04b5fe0ffb4c873a8d839ededcc616658e88af346a5c6a709c37eec8088486b4.wasm",
"vp_implicit.wasm": "vp_implicit.1e8355b50da06a5dcf9d2a8ab8ddc440f486ce039538dee415ab8625b1b11bae.wasm",
"vp_masp.wasm": "vp_masp.7487613c4391eef753360c55e63979fad3855259f2fdb0e945fe702342ef5979.wasm",
"vp_testnet_faucet.wasm": "vp_testnet_faucet.d3cafc4d31f1081a8cedfbfdb45e674235231716668a6b1309beece16fe5ea5d.wasm",
"vp_token.wasm": "vp_token.495362b8949a5f77da12c5562c38e25584a7477cf6e1b229a8b209a67e6504d0.wasm",
"vp_user.wasm": "vp_user.c7b65fe31adb835d341ef82a6f02f72ee6c6bf457c22ad24422acb3d54387517.wasm",
"vp_validator.wasm": "vp_validator.64283182a94de72f35364414040f780c2d51d629e73e915f1803c9e71a2f5fd2.wasm"
}

0 comments on commit a458b55

Please sign in to comment.