Skip to content

Commit

Permalink
update to latest proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Nov 21, 2024
1 parent efddbc6 commit cd4bb7e
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 77 deletions.
7 changes: 2 additions & 5 deletions lib/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ where
let two_way_peg_data = mainchain
.get_two_way_peg_data(last_known_deposit_info, block_hash)
.await?;
let mut block_deposits = LinkedHashMap::<_, _>::from_iter(
two_way_peg_data
.deposits()
.map(|(block_hash, deposits)| (block_hash, deposits.clone())),
);
let mut block_deposits =
LinkedHashMap::<_, _>::from_iter(two_way_peg_data.into_deposits());
let mut rwtxn = env.write_txn()?;
let () = archive
.main_ancestors(&rwtxn, block_hash)
Expand Down
58 changes: 28 additions & 30 deletions lib/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,14 @@ impl State {
);
}
}
for (_, m6id, event) in two_way_peg_data.withdrawal_bundle_events() {
for (_, event) in two_way_peg_data.withdrawal_bundle_events() {
match event.status {
WithdrawalBundleStatus::Submitted => {
let Some((bundle, bundle_block_height)) =
self.pending_withdrawal_bundle.get(rwtxn, &UnitKey)?
else {
if let Some((_bundle, bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
{
// Already applied
assert_eq!(
Expand All @@ -755,22 +755,22 @@ impl State {
continue;
}
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
assert_eq!(bundle_block_height, block_height - 2);
if bundle.compute_m6id() != *m6id {
if bundle.compute_m6id() != event.m6id {
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
}
tracing::debug!(
%m6id,
m6id = %event.m6id,
"Withdrawal bundle successfully submitted"
);
self.withdrawal_bundles.put(
rwtxn,
m6id,
&event.m6id,
&(
bundle,
RollBack::new(
Expand All @@ -783,10 +783,10 @@ impl State {
}
WithdrawalBundleStatus::Confirmed => {
let Some((bundle, mut bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
else {
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
if bundle_status.latest().value
Expand All @@ -805,16 +805,16 @@ impl State {
.expect("Push confirmed status should be valid");
self.withdrawal_bundles.put(
rwtxn,
m6id,
&event.m6id,
&(bundle, bundle_status),
)?;
}
WithdrawalBundleStatus::Failed => {
let Some((bundle, mut bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
else {
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
if bundle_status.latest().value
Expand Down Expand Up @@ -846,13 +846,13 @@ impl State {
.get(rwtxn, &UnitKey)?
{
latest_failed_m6id
.push(*m6id, block_height)
.push(event.m6id, block_height)
.expect(
"Push latest failed m6id should be valid",
);
latest_failed_m6id
} else {
RollBack::new(*m6id, block_height)
RollBack::new(event.m6id, block_height)
};
self.latest_failed_withdrawal_bundle.put(
rwtxn,
Expand All @@ -861,7 +861,7 @@ impl State {
)?;
self.withdrawal_bundles.put(
rwtxn,
m6id,
&event.m6id,
&(bundle, bundle_status),
)?;
}
Expand Down Expand Up @@ -893,24 +893,22 @@ impl State {
let mut accumulator_del = HashSet::<NodeHash>::new();

// Restore pending withdrawal bundle
for (_, m6id, event) in
two_way_peg_data.withdrawal_bundle_events().rev()
{
for (_, event) in two_way_peg_data.withdrawal_bundle_events().rev() {
match event.status {
WithdrawalBundleStatus::Submitted => {
let Some((bundle, bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
else {
if let Some((bundle, _)) = self
.pending_withdrawal_bundle
.get(rwtxn, &UnitKey)?
&& bundle.compute_m6id() == *m6id
&& bundle.compute_m6id() == event.m6id
{
// Already applied
continue;
}
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
let bundle_status = bundle_status.latest();
Expand All @@ -924,14 +922,14 @@ impl State {
&UnitKey,
&(bundle, bundle_status.height - 2),
)?;
self.withdrawal_bundles.delete(rwtxn, m6id)?;
self.withdrawal_bundles.delete(rwtxn, &event.m6id)?;
}
WithdrawalBundleStatus::Confirmed => {
let Some((bundle, bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
else {
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
let (prev_bundle_status, latest_bundle_status) =
Expand All @@ -956,16 +954,16 @@ impl State {
);
self.withdrawal_bundles.put(
rwtxn,
m6id,
&event.m6id,
&(bundle, prev_bundle_status),
)?;
}
WithdrawalBundleStatus::Failed => {
let Some((bundle, bundle_status)) =
self.withdrawal_bundles.get(rwtxn, m6id)?
self.withdrawal_bundles.get(rwtxn, &event.m6id)?
else {
return Err(Error::UnknownWithdrawalBundle {
m6id: *m6id,
m6id: event.m6id,
});
};
let (prev_bundle_status, latest_bundle_status) =
Expand All @@ -992,7 +990,7 @@ impl State {
{
let spent_output = SpentOutput {
output: output.clone(),
inpoint: InPoint::Withdrawal { m6id: *m6id },
inpoint: InPoint::Withdrawal { m6id: event.m6id },
};
self.stxos.put(rwtxn, outpoint, &spent_output)?;
if self.utxos.delete(rwtxn, outpoint)? {
Expand All @@ -1008,15 +1006,15 @@ impl State {
}
self.withdrawal_bundles.put(
rwtxn,
m6id,
&event.m6id,
&(bundle, prev_bundle_status),
)?;
let (prev_latest_failed_m6id, latest_failed_m6id) = self
.latest_failed_withdrawal_bundle
.get(rwtxn, &UnitKey)?
.expect("latest failed withdrawal bundle should exist")
.pop();
assert_eq!(latest_failed_m6id.value, *m6id);
assert_eq!(latest_failed_m6id.value, event.m6id);
assert_eq!(latest_failed_m6id.height, block_height);
if let Some(prev_latest_failed_m6id) =
prev_latest_failed_m6id
Expand Down
Loading

0 comments on commit cd4bb7e

Please sign in to comment.