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 5, 2023
2 parents 1956cba + 62dd559 commit 6be5166
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.1ac4fc75655415a08a628bc07133d0141ade4086253b4f96673e9eb7da45726a.wasm",
"tx_change_validator_commission.wasm": "tx_change_validator_commission.4dcd692eeb90658506d2eb284c7da90c08bb8d2a625f914573e99efebbfb94ed.wasm",
"tx_ibc.wasm": "tx_ibc.729f25abd2e77152eeec492c01a3d79db56c0ddb9ff235cb12590037387f4aa1.wasm",
"tx_init_account.wasm": "tx_init_account.53ef514d4f5eb4cb4a8a83894be08833777e4eb3aec7c7edbd147991b7d275f4.wasm",
"tx_init_proposal.wasm": "tx_init_proposal.008bd96153886cdeff1ad68fc0978d35ad7a4edc19becf71d8f8c3e5d1f4b1a5.wasm",
"tx_init_validator.wasm": "tx_init_validator.d87634e95f47c4ed43806a23f2cdcea5e3c8c964987ab4059013a531a3cf91ae.wasm",
"tx_reveal_pk.wasm": "tx_reveal_pk.0b1b66ec606b0ce85717e8a026872ef7f6edb936510d60abf0126d2936e34c5a.wasm",
"tx_transfer.wasm": "tx_transfer.57f62e5edc9ac962add374599cccf9de2d5b8341cfcbc6c11021f6947253da9a.wasm",
"tx_unbond.wasm": "tx_unbond.30f386ba0b79017c060e9e828f61b2f25590999c3e321ea33f06a7bcf2f0f63e.wasm",
"tx_update_vp.wasm": "tx_update_vp.24b8501c7df4ee482fbab8411a5e8666d36267302783998e6dd3ccc92a2eb802.wasm",
"tx_vote_proposal.wasm": "tx_vote_proposal.e38b9a1e138aba5482e4429522218172a1c5ef91279e7b2c213fe2749c9220e7.wasm",
"tx_withdraw.wasm": "tx_withdraw.2d54fbffe9ab316cf63122ffe2f6c9b6f43e2da0145a5ea75dd99d5e86018fb0.wasm",
"vp_implicit.wasm": "vp_implicit.2057db599475eb1dc96e5b40c9f39eec8748f92bfd45713e85abea9c5b9a3021.wasm",
"vp_masp.wasm": "vp_masp.3f1f0b555faaf9260b19b04e8277fc52889a6cb0f8bd225b08c4777dba23a65d.wasm",
"vp_testnet_faucet.wasm": "vp_testnet_faucet.05c6758273d11980f03bf58af4edeacb935a22c89aa915c9767825924b5bd00f.wasm",
"vp_token.wasm": "vp_token.61e54faa78931c6fd3cd4ef3d03495d735ed1052037f3cc395079d34db63de16.wasm",
"vp_user.wasm": "vp_user.f46b6efec59564fe82aa7e8fd1cfa503f4c86ae881b3704ee6080998fa0313dc.wasm",
"vp_validator.wasm": "vp_validator.78a51f16ad2ab2dcc10c77c66b31d3bd7f5e2c0d2181b1ef4bf52049f9469ab2.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 6be5166

Please sign in to comment.