Skip to content

Commit 86943e6

Browse files
committed
fix(validations): fix missing data request state in validations for instantaneous data requests (e.g., TooManyWitnesses)
1 parent 2662c47 commit 86943e6

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

node/src/actors/chain_manager/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl ChainManager {
710710
rep_engine,
711711
epoch_constants,
712712
&self.chain_state.unspent_outputs_pool,
713-
&self.chain_state.data_request_pool,
713+
&mut self.chain_state.data_request_pool,
714714
vrf_ctx,
715715
block_number,
716716
&chain_info.consensus_constants,
@@ -866,6 +866,7 @@ impl ChainManager {
866866
// in this block candidate.
867867
let mut transaction_visitor = PriorityVisitor::default();
868868

869+
let block_number = self.chain_state.block_number();
869870
match process_validations(
870871
&block,
871872
current_epoch,
@@ -874,11 +875,11 @@ impl ChainManager {
874875
rep_engine,
875876
self.epoch_constants.unwrap(),
876877
&self.chain_state.unspent_outputs_pool,
877-
&self.chain_state.data_request_pool,
878+
&mut self.chain_state.data_request_pool,
878879
// The unwrap is safe because if there is no VRF context,
879880
// the actor should have stopped execution
880881
self.vrf_ctx.as_mut().expect("No initialized VRF context"),
881-
self.chain_state.block_number(),
882+
block_number,
882883
&chain_info.consensus_constants,
883884
false,
884885
&active_wips,
@@ -2113,7 +2114,7 @@ impl ChainManager {
21132114
let mut signatures_to_verify = vec![];
21142115
let res = validate_block_transactions(
21152116
&act.chain_state.unspent_outputs_pool,
2116-
&act.chain_state.data_request_pool,
2117+
&mut act.chain_state.data_request_pool,
21172118
&block,
21182119
vrf_input,
21192120
&mut signatures_to_verify,
@@ -2892,7 +2893,7 @@ pub fn process_validations(
28922893
rep_eng: &ReputationEngine,
28932894
epoch_constants: EpochConstants,
28942895
utxo_set: &UnspentOutputsPool,
2895-
dr_pool: &DataRequestPool,
2896+
dr_pool: &mut DataRequestPool,
28962897
vrf_ctx: &mut VrfCtx,
28972898
block_number: u32,
28982899
consensus_constants: &ConsensusConstants,

validations/src/validations.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ pub fn update_utxo_diff<'a, IterInputs, IterOutputs>(
16751675
#[allow(clippy::too_many_arguments)]
16761676
pub fn validate_block_transactions(
16771677
utxo_set: &UnspentOutputsPool,
1678-
dr_pool: &DataRequestPool,
1678+
dr_pool: &mut DataRequestPool,
16791679
block: &Block,
16801680
vrf_input: CheckpointVRF,
16811681
signatures_to_verify: &mut Vec<SignaturesToVerify>,
@@ -1845,6 +1845,30 @@ pub fn validate_block_transactions(
18451845
}
18461846
let re_hash_merkle_root = re_mt.root();
18471847

1848+
for transaction in &block.txns.data_request_txns {
1849+
let dr_tx_hash = transaction.hash();
1850+
if !dr_pool.data_request_pool.contains_key(&dr_tx_hash)
1851+
&& data_request_has_too_many_witnesses(
1852+
&transaction.body.dr_output,
1853+
stakes.validator_count(),
1854+
Some(epoch),
1855+
)
1856+
{
1857+
log::debug!(
1858+
"Temporarily adding data request {} to data request pool for validation purposes",
1859+
transaction.hash()
1860+
);
1861+
if let Err(e) = dr_pool.process_data_request(transaction, epoch, &block.hash()) {
1862+
log::error!("Error adding data request to the data request pool: {}", e);
1863+
}
1864+
if let Some(dr_state) = dr_pool.data_request_state_mutable(&dr_tx_hash) {
1865+
dr_state.update_stage(0, true);
1866+
} else {
1867+
log::error!("Could not find data request state");
1868+
}
1869+
}
1870+
}
1871+
18481872
// Validate tally transactions in a block
18491873
let mut ta_mt = ProgressiveMerkleTree::sha256();
18501874
let mut tally_hs = HashSet::with_capacity(block.txns.tally_txns.len());

0 commit comments

Comments
 (0)