Skip to content

Commit

Permalink
Merge pull request #11631 from MinaProtocol/fix/transaction-pool-nonc…
Browse files Browse the repository at this point in the history
…e-tracking

Update pool based on expected vs actual target nonces of parties transaction
  • Loading branch information
deepthiskumar authored Aug 11, 2022
2 parents 4c810b1 + 7ead53d commit 0725754
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 76 deletions.
7 changes: 4 additions & 3 deletions src/lib/mina_base/parties.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,11 @@ let fee (t : t) : Currency.Fee.t = t.fee_payer.body.fee

let fee_payer_party ({ fee_payer; _ } : t) = fee_payer

let application_nonce (t : t) : Account.Nonce.t = (fee_payer_party t).body.nonce
let applicable_at_nonce (t : t) : Account.Nonce.t =
(fee_payer_party t).body.nonce

let target_nonce (t : t) : Account.Nonce.t =
let base_nonce = Account.Nonce.succ (application_nonce t) in
let target_nonce_on_success (t : t) : Account.Nonce.t =
let base_nonce = Account.Nonce.succ (applicable_at_nonce t) in
let fee_payer_pubkey = t.fee_payer.body.public_key in
let fee_payer_party_increments =
List.count (Call_forest.to_list t.other_parties) ~f:(fun p ->
Expand Down
12 changes: 7 additions & 5 deletions src/lib/mina_base/user_command.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,22 @@ let fee_payer (t : t) =
Parties.fee_payer p

(** The application nonce is the nonce of the fee payer at which a user command can be applied. *)
let application_nonce (t : t) =
let applicable_at_nonce (t : t) =
match t with
| Signed_command x ->
Signed_command.nonce x
| Parties p ->
Parties.application_nonce p
Parties.applicable_at_nonce p

(** The target nonce is what the nonce of the fee payer will be after a user command is applied. *)
let target_nonce (t : t) =
let expected_target_nonce t = Account.Nonce.succ (applicable_at_nonce t)

(** The target nonce is what the nonce of the fee payer will be after a user command is successfully applied. *)
let target_nonce_on_success (t : t) =
match t with
| Signed_command x ->
Account.Nonce.succ (Signed_command.nonce x)
| Parties p ->
Parties.target_nonce p
Parties.target_nonce_on_success p

let fee_token (t : t) =
match t with
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mina_lib/mina_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ let get_inferred_nonce_from_transaction_pool_and_ledger t
List.last pooled_transactions
|> Option.map
~f:
(Fn.compose User_command.target_nonce
(Fn.compose User_command.expected_target_nonce
Transaction_hash.User_command_with_valid_signature.command )
in
match txn_pool_nonce with
Expand Down
Loading

0 comments on commit 0725754

Please sign in to comment.