Skip to content

Commit 6b8ee53

Browse files
committed
Implement object balance withdraw
1 parent d8a44d6 commit 6b8ee53

File tree

15 files changed

+390
-86
lines changed

15 files changed

+390
-86
lines changed

crates/sui-core/src/authority.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,9 @@ pub struct ExecutionEnv {
800800
pub expected_effects_digest: Option<TransactionEffectsDigest>,
801801
/// The source of the scheduling of the transaction.
802802
pub scheduling_source: SchedulingSource,
803-
/// Status of the balance withdraw scheduling of the transaction.
804-
pub withdraw_status: BalanceWithdrawStatus,
803+
/// Status of the balance withdraw scheduling of the transaction,
804+
/// including both address and object balance withdraws.
805+
pub balance_withdraw_status: BalanceWithdrawStatus,
805806
/// Transactions that must finish before this transaction can be executed.
806807
/// Used to schedule barrier transactions after non-exclusive writes.
807808
pub barrier_dependencies: Vec<TransactionDigest>,
@@ -813,7 +814,7 @@ impl Default for ExecutionEnv {
813814
assigned_versions: Default::default(),
814815
expected_effects_digest: None,
815816
scheduling_source: SchedulingSource::NonFastPath,
816-
withdraw_status: BalanceWithdrawStatus::NoWithdraw,
817+
balance_withdraw_status: BalanceWithdrawStatus::Unknown,
817818
barrier_dependencies: Default::default(),
818819
}
819820
}
@@ -842,13 +843,8 @@ impl ExecutionEnv {
842843
self
843844
}
844845

845-
pub fn with_sufficient_balance(mut self) -> Self {
846-
self.withdraw_status = BalanceWithdrawStatus::SufficientBalance;
847-
self
848-
}
849-
850846
pub fn with_insufficient_balance(mut self) -> Self {
851-
self.withdraw_status = BalanceWithdrawStatus::InsufficientBalance;
847+
self.balance_withdraw_status = BalanceWithdrawStatus::InsufficientBalance;
852848
self
853849
}
854850

@@ -1744,7 +1740,7 @@ impl AuthorityState {
17441740
&self,
17451741
tx_lock: &CertLockGuard,
17461742
certificate: &VerifiedExecutableTransaction,
1747-
assigned_shared_object_versions: AssignedVersions,
1743+
assigned_shared_object_versions: &AssignedVersions,
17481744
epoch_store: &Arc<AuthorityPerEpochStore>,
17491745
) -> SuiResult<InputObjects> {
17501746
let _scope = monitored_scope("Execution::load_input_objects");
@@ -1757,7 +1753,7 @@ impl AuthorityState {
17571753
&certificate.key(),
17581754
tx_lock,
17591755
input_objects,
1760-
&assigned_shared_object_versions,
1756+
assigned_shared_object_versions,
17611757
epoch_store.epoch(),
17621758
)
17631759
}
@@ -1852,7 +1848,7 @@ impl AuthorityState {
18521848
let input_objects = match self.read_objects_for_execution(
18531849
tx_guard.as_lock_guard(),
18541850
certificate,
1855-
execution_env.assigned_versions,
1851+
&execution_env.assigned_versions,
18561852
epoch_store,
18571853
) {
18581854
Ok(objects) => objects,
@@ -1888,7 +1884,7 @@ impl AuthorityState {
18881884
certificate,
18891885
input_objects,
18901886
expected_effects_digest,
1891-
execution_env.withdraw_status,
1887+
execution_env,
18921888
epoch_store,
18931889
)
18941890
}
@@ -2001,7 +1997,7 @@ impl AuthorityState {
20011997
certificate: &VerifiedExecutableTransaction,
20021998
input_objects: InputObjects,
20031999
expected_effects_digest: Option<TransactionEffectsDigest>,
2004-
withdraw_status: BalanceWithdrawStatus,
2000+
execution_env: ExecutionEnv,
20052001
epoch_store: &Arc<AuthorityPerEpochStore>,
20062002
) -> ExecutionOutput<(
20072003
TransactionOutputs,
@@ -2043,7 +2039,7 @@ impl AuthorityState {
20432039
&tx_digest,
20442040
&input_objects,
20452041
self.config.certificate_deny_config.certificate_deny_set(),
2046-
&withdraw_status,
2042+
&execution_env.balance_withdraw_status,
20472043
);
20482044
let execution_params = match early_execution_error {
20492045
Some(error) => ExecutionOrEarlyError::Err(error),
@@ -2052,8 +2048,7 @@ impl AuthorityState {
20522048

20532049
let tracking_store = TrackingBackingStore::new(self.get_backing_store().as_ref());
20542050

2055-
#[allow(unused_mut)]
2056-
let (inner_temp_store, _, mut effects, timings, execution_error_opt) =
2051+
let (inner_temp_store, _, effects, timings, execution_error_opt) =
20572052
epoch_store.executor().execute_transaction_to_effects(
20582053
&tracking_store,
20592054
protocol_config,
@@ -2078,6 +2073,13 @@ impl AuthorityState {
20782073
&mut None,
20792074
);
20802075

2076+
if !self
2077+
.execution_scheduler
2078+
.should_commit_object_balance_withdraws(certificate, &effects, &execution_env)
2079+
{
2080+
return ExecutionOutput::RetryLater;
2081+
}
2082+
20812083
if let Some(expected_effects_digest) = expected_effects_digest
20822084
&& effects.digest() != expected_effects_digest
20832085
{
@@ -2213,7 +2215,7 @@ impl AuthorityState {
22132215
certificate,
22142216
input_objects,
22152217
None,
2216-
BalanceWithdrawStatus::NoWithdraw,
2218+
ExecutionEnv::default(),
22172219
epoch_store,
22182220
)
22192221
.unwrap();
@@ -2357,7 +2359,7 @@ impl AuthorityState {
23572359
&checked_input_objects,
23582360
self.config.certificate_deny_config.certificate_deny_set(),
23592361
// TODO(address-balances): Mimic withdraw scheduling and pass the result.
2360-
&BalanceWithdrawStatus::NoWithdraw,
2362+
&BalanceWithdrawStatus::Unknown,
23612363
);
23622364
let execution_params = match early_execution_error {
23632365
Some(error) => ExecutionOrEarlyError::Err(error),
@@ -2565,7 +2567,7 @@ impl AuthorityState {
25652567
&checked_input_objects,
25662568
self.config.certificate_deny_config.certificate_deny_set(),
25672569
// TODO(address-balances): Mimic withdraw scheduling and pass the result.
2568-
&BalanceWithdrawStatus::NoWithdraw,
2570+
&BalanceWithdrawStatus::Unknown,
25692571
);
25702572
let execution_params = match early_execution_error {
25712573
Some(error) => ExecutionOrEarlyError::Err(error),
@@ -2810,7 +2812,7 @@ impl AuthorityState {
28102812
&checked_input_objects,
28112813
self.config.certificate_deny_config.certificate_deny_set(),
28122814
// TODO(address-balances): Mimic withdraw scheduling and pass the result.
2813-
&BalanceWithdrawStatus::NoWithdraw,
2815+
&BalanceWithdrawStatus::Unknown,
28142816
);
28152817
let execution_params = match early_execution_error {
28162818
Some(error) => ExecutionOrEarlyError::Err(error),
@@ -5950,7 +5952,7 @@ impl AuthorityState {
59505952
let input_objects = self.read_objects_for_execution(
59515953
&tx_lock,
59525954
&executable_tx,
5953-
assigned_versions,
5955+
&assigned_versions,
59545956
epoch_store,
59555957
)?;
59565958

@@ -5960,7 +5962,7 @@ impl AuthorityState {
59605962
&executable_tx,
59615963
input_objects,
59625964
None,
5963-
BalanceWithdrawStatus::NoWithdraw,
5965+
ExecutionEnv::default(),
59645966
epoch_store,
59655967
)
59665968
.unwrap();

crates/sui-core/src/checkpoints/checkpoint_executor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,8 @@ impl CheckpointExecutor {
876876
.with_barrier_dependencies(barrier_deps);
877877

878878
// Check if the expected effects indicate insufficient balance
879-
if let ExecutionStatus::Failure {
880-
error: ExecutionFailureStatus::InsufficientBalanceForWithdraw,
879+
if let &ExecutionStatus::Failure {
880+
error: ExecutionFailureStatus::InsufficientFunds,
881881
..
882882
} = effects.status()
883883
{

crates/sui-core/src/execution_scheduler/balance_withdraw_scheduler/e2e_tests.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl TestEnv {
158158
let cert = self.receive_certificate().await.unwrap();
159159
results.insert(
160160
*cert.certificate.digest(),
161-
cert.execution_env.withdraw_status,
161+
cert.execution_env.balance_withdraw_status,
162162
);
163163
}
164164
assert_eq!(results, expected_results);
@@ -212,14 +212,8 @@ async fn test_withdraw_schedule_e2e() {
212212
test_env.enqueue_transactions(transactions.clone());
213213
test_env
214214
.expect_withdraw_results(BTreeMap::from([
215-
(
216-
*transactions[0].digest(),
217-
BalanceWithdrawStatus::SufficientBalance,
218-
),
219-
(
220-
*transactions[1].digest(),
221-
BalanceWithdrawStatus::SufficientBalance,
222-
),
215+
(*transactions[0].digest(), BalanceWithdrawStatus::Unknown),
216+
(*transactions[1].digest(), BalanceWithdrawStatus::Unknown),
223217
(
224218
*transactions[2].digest(),
225219
BalanceWithdrawStatus::InsufficientBalance,
@@ -235,10 +229,7 @@ async fn test_withdraw_schedule_e2e() {
235229
test_env.settle_balances(BTreeMap::from([(test_env.account_objects[0], -500)]));
236230
test_env
237231
.expect_withdraw_results(BTreeMap::from([
238-
(
239-
*transactions[0].digest(),
240-
BalanceWithdrawStatus::SufficientBalance,
241-
),
232+
(*transactions[0].digest(), BalanceWithdrawStatus::Unknown),
242233
(
243234
*transactions[1].digest(),
244235
BalanceWithdrawStatus::InsufficientBalance,

crates/sui-core/src/execution_scheduler/balance_withdraw_scheduler/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use sui_types::{
77
accumulator_root::AccumulatorObjId, base_types::SequenceNumber, digests::TransactionDigest,
88
};
99

10-
mod balance_read;
10+
pub mod balance_read;
1111
mod eager_scheduler;
1212
mod naive_scheduler;
13+
pub(crate) mod object_balance_withdraw_scheduler;
1314
pub(crate) mod scheduler;
1415
#[cfg(test)]
1516
mod tests;

0 commit comments

Comments
 (0)