Skip to content

Commit

Permalink
Simulate: Enable on follower node & allow specifying starting round (a…
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos authored Aug 29, 2023
1 parent 10f2f55 commit 2670e94
Show file tree
Hide file tree
Showing 21 changed files with 1,431 additions and 1,119 deletions.
4 changes: 4 additions & 0 deletions cmd/goal/clerk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
requestFilename string
requestOutFilename string

simulateStartRound uint64
simulateAllowEmptySignatures bool
simulateAllowMoreLogging bool
simulateAllowMoreOpcodeBudget bool
Expand Down Expand Up @@ -164,6 +165,7 @@ func init() {
simulateCmd.Flags().StringVar(&requestFilename, "request", "", "Simulate request object to run. Mutually exclusive with --txfile")
simulateCmd.Flags().StringVar(&requestOutFilename, "request-only-out", "", "Filename for writing simulate request object. If provided, the command will only write the request object and exit. No simulation will happen")
simulateCmd.Flags().StringVarP(&outFilename, "result-out", "o", "", "Filename for writing simulation result")
simulateCmd.Flags().Uint64Var(&simulateStartRound, "round", 0, "Specify the round after which the simulation will take place. If not specified, the simulation will take place after the latest round.")
simulateCmd.Flags().BoolVar(&simulateAllowEmptySignatures, "allow-empty-signatures", false, "Allow transactions without signatures to be simulated as if they had correct signatures")
simulateCmd.Flags().BoolVar(&simulateAllowMoreLogging, "allow-more-logging", false, "Lift the limits on log opcode during simulation")
simulateCmd.Flags().BoolVar(&simulateAllowMoreOpcodeBudget, "allow-more-opcode-budget", false, "Apply max extra opcode budget for apps per transaction group (default 320000) during simulation")
Expand Down Expand Up @@ -1285,6 +1287,7 @@ var simulateCmd = &cobra.Command{
Txns: txgroup,
},
},
Round: basics.Round(simulateStartRound),
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
AllowUnnamedResources: simulateAllowUnnamedResources,
Expand All @@ -1310,6 +1313,7 @@ var simulateCmd = &cobra.Command{
Txns: txgroup,
},
},
Round: basics.Round(simulateStartRound),
AllowEmptySignatures: simulateAllowEmptySignatures,
AllowMoreLogging: simulateAllowMoreLogging,
AllowUnnamedResources: simulateAllowUnnamedResources,
Expand Down
4 changes: 4 additions & 0 deletions daemon/algod/api/algod.oas2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,10 @@
"$ref": "#/definitions/SimulateRequestTransactionGroup"
}
},
"round": {
"description": "If provided, specifies the round preceding the simulation. State changes through this round will be used to run this simulation. Usually only the 4 most recent rounds will be available (controlled by the node config value MaxAcctLookback). If not specified, defaults to the latest available round.",
"type": "integer"
},
"allow-empty-signatures": {
"description": "Allows transactions without signatures to be simulated as if they had correct signatures.",
"type": "boolean"
Expand Down
4 changes: 4 additions & 0 deletions daemon/algod/api/algod.oas3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,10 @@
"description": "Applies extra opcode budget during simulation for each transaction group.",
"type": "integer"
},
"round": {
"description": "If provided, specifies the round preceding the simulation. State changes through this round will be used to run this simulation. Usually only the 4 most recent rounds will be available (controlled by the node config value MaxAcctLookback). If not specified, defaults to the latest available round.",
"type": "integer"
},
"txn-groups": {
"description": "The transaction groups to simulate.",
"items": {
Expand Down
398 changes: 200 additions & 198 deletions daemon/algod/api/server/v2/generated/data/routes.go

Large diffs are not rendered by default.

399 changes: 200 additions & 199 deletions daemon/algod/api/server/v2/generated/experimental/routes.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions daemon/algod/api/server/v2/generated/model/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

400 changes: 201 additions & 199 deletions daemon/algod/api/server/v2/generated/nonparticipating/private/routes.go

Large diffs are not rendered by default.

496 changes: 249 additions & 247 deletions daemon/algod/api/server/v2/generated/nonparticipating/public/routes.go

Large diffs are not rendered by default.

405 changes: 203 additions & 202 deletions daemon/algod/api/server/v2/generated/participating/private/routes.go

Large diffs are not rendered by default.

126 changes: 64 additions & 62 deletions daemon/algod/api/server/v2/generated/participating/public/routes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions daemon/algod/api/server/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,7 @@ type PreEncodedSimulateRequestTransactionGroup struct {
// PreEncodedSimulateRequest mirrors model.SimulateRequest
type PreEncodedSimulateRequest struct {
TxnGroups []PreEncodedSimulateRequestTransactionGroup `codec:"txn-groups"`
Round basics.Round `codec:"round,omitempty"`
AllowEmptySignatures bool `codec:"allow-empty-signatures,omitempty"`
AllowMoreLogging bool `codec:"allow-more-logging,omitempty"`
AllowUnnamedResources bool `codec:"allow-unnamed-resources,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions daemon/algod/api/server/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ func convertSimulationRequest(request PreEncodedSimulateRequest) simulation.Requ
}
return simulation.Request{
TxnGroups: txnGroups,
Round: request.Round,
AllowEmptySignatures: request.AllowEmptySignatures,
AllowMoreLogging: request.AllowMoreLogging,
AllowUnnamedResources: request.AllowUnnamedResources,
Expand Down
16 changes: 16 additions & 0 deletions ledger/acctupdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@ func (au *accountUpdates) LatestTotals() (basics.Round, ledgercore.AccountTotals
return au.latestTotalsImpl()
}

// Totals returns the totals of all accounts for the given round
func (au *accountUpdates) Totals(rnd basics.Round) (ledgercore.AccountTotals, error) {
au.accountsMu.RLock()
defer au.accountsMu.RUnlock()
return au.totalsImpl(rnd)
}

// ReadCloseSizer interface implements the standard io.Reader and io.Closer as well
// as supporting the Size() function that let the caller know what the size of the stream would be (in bytes).
type ReadCloseSizer interface {
Expand Down Expand Up @@ -722,6 +729,15 @@ func (au *accountUpdates) latestTotalsImpl() (basics.Round, ledgercore.AccountTo
return rnd, au.roundTotals[offset], nil
}

// totalsImpl returns the totals of all accounts for the given round
func (au *accountUpdates) totalsImpl(rnd basics.Round) (ledgercore.AccountTotals, error) {
offset, err := au.roundOffset(rnd)
if err != nil {
return ledgercore.AccountTotals{}, err
}
return au.roundTotals[offset], nil
}

// initializeFromDisk performs the atomic operation of loading the accounts data information from disk
// and preparing the accountUpdates for operation.
func (au *accountUpdates) initializeFromDisk(l ledgerForTracker, lastBalancesRound basics.Round) error {
Expand Down
7 changes: 7 additions & 0 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,13 @@ func (l *Ledger) LatestTotals() (basics.Round, ledgercore.AccountTotals, error)
return l.accts.LatestTotals()
}

// Totals returns the totals of all accounts for the given round.
func (l *Ledger) Totals(rnd basics.Round) (ledgercore.AccountTotals, error) {
l.trackerMu.RLock()
defer l.trackerMu.RUnlock()
return l.accts.Totals(rnd)
}

// OnlineCirculation returns the online totals of all accounts at the end of round rnd.
// It implements agreement's calls for Circulation(rnd)
func (l *Ledger) OnlineCirculation(rnd basics.Round, voteRnd basics.Round) (basics.MicroAlgos, error) {
Expand Down
Loading

0 comments on commit 2670e94

Please sign in to comment.