-
Notifications
You must be signed in to change notification settings - Fork 0
feat: saexec package
#20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
171cd6f
feat: `saexec` package
ARR4N 5eca897
Merge branch 'main' into arr4n/saexec
ARR4N 1fd6ecf
refactor!: use MIT contract for testing
ARR4N bd0a0c3
fix: log errored tx execution and continue
ARR4N f3ca5e7
doc: fix misspelling
ARR4N d04027f
refactor: `escrow` package provides contract helpers
ARR4N f442e76
fix: remove duplicated log fields
ARR4N d74bccc
refactor: `newSUT()` constructs memory database
ARR4N 90a49eb
feat: `saetest.TBLogger` errors cancel context
ARR4N 0245a1b
feat: user-defined before- and after-block hooks
ARR4N fc2f6fc
Merge branch 'main' into arr4n/saexec
ARR4N 0183d17
feat: `hook.Points` supports sub-second block times
ARR4N e7772ce
chore: placate the linter
ARR4N 03aa639
chore: if `golangci-lint` just said what it wanted then this would al…
ARR4N 472f9fb
chore: Linty McLintface
ARR4N 433494f
fix: contextual opcodes, particularly `BLOCKHASH`
ARR4N d56614d
refactor: `defer` unlocking `CondVar.L`
ARR4N f7bcfb1
chore: no points for guessing
ARR4N 476e73c
refactor: use `zap.Stringer` for block hash
ARR4N 18ee4b5
refactor: move `TimeNotThreadsafe` to test file and un-export
ARR4N 6feac2a
refactor: simplify `ChainBuilder.NewBlock` options handling
ARR4N eb40cdd
test: `BASEFEE` op code
ARR4N 9e314c4
test: additional contextual op codes
ARR4N e042828
refactor: exponential backoff for `Enqueue()` wait warning
ARR4N 894b190
doc: permalink to `Escrow.sol`
ARR4N 88d0728
refactor: return `consensus.Engine(nil)`
ARR4N f55b3b9
refactor: correct parenthesis matching
ARR4N 00e5417
refactor: stop embedding `BlockSource` in `chainContext`
ARR4N c1f12b8
fix: `ChainBuilder` uses `sync.Map` for blocks stored by hash
ARR4N 4fe05c1
refactor: remove specific type from unindexed `for range`
ARR4N 0fafec4
refactor: determine contract address from `Nonce()` value of tx
ARR4N e64de9c
refactor: use `math.Pow()` for calculating gas price in test
ARR4N beed9ca
refactor: remove `executionScratchSpace` and `Executor.init()`
ARR4N c6d1ef2
refactor: make gas clock internal variable in `Executor.execute()`
ARR4N 48342cd
fix: `ApplyTransaction` errors are `FATAL`
ARR4N caf3242
feat: `snapshot.Tree.Cap(..., 0)` on shutdown to persist top layer
ARR4N 0e3a778
refactor: review suggestions
ARR4N 06256a9
refactor!: don't disable snapshot generation on shutdown
ARR4N f41f1a7
refactor: base block-ordering assertion on parent hash
ARR4N File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| package cmputils | ||
|
|
||
| import ( | ||
| "math/big" | ||
|
|
||
| "github.com/ava-labs/libevm/core/types" | ||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| // BigInts returns a [cmp.Comparer] for [big.Int] pointers. A nil pointer is not | ||
| // equal to zero. | ||
| func BigInts() cmp.Option { | ||
| return ComparerWithNilCheck(func(a, b *big.Int) bool { | ||
| return a.Cmp(b) == 0 | ||
| }) | ||
| } | ||
|
|
||
| // BlocksByHash returns a [cmp.Comparer] for [types.Block] pointers, equating | ||
| // them by hash alone. | ||
| func BlocksByHash() cmp.Option { | ||
| return ComparerWithNilCheck(func(b, c *types.Block) bool { | ||
| return b.Hash() == c.Hash() | ||
| }) | ||
| } | ||
|
|
||
| // ReceiptsByTxHash returns a [cmp.Comparer] for [types.Receipt] pointers, | ||
| // equating them by transaction hash alone. | ||
| func ReceiptsByTxHash() cmp.Option { | ||
| return ComparerWithNilCheck(func(r, s *types.Receipt) bool { | ||
| return r.TxHash == s.TxHash | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| // Package hook defines points in an SAE block's lifecycle at which common or | ||
| // user-injected behaviour needs to be performed. Functions in this package | ||
| // SHOULD be called by all code dealing with a block at the respective point in | ||
| // its lifecycle, be that during validation, execution, or otherwise. | ||
| package hook | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/ava-labs/avalanchego/vms/components/gas" | ||
| "github.com/ava-labs/libevm/core/state" | ||
| "github.com/ava-labs/libevm/core/types" | ||
| "github.com/ava-labs/libevm/params" | ||
|
|
||
| "github.com/ava-labs/strevm/blocks" | ||
| "github.com/ava-labs/strevm/gastime" | ||
| "github.com/ava-labs/strevm/intmath" | ||
| saeparams "github.com/ava-labs/strevm/params" | ||
| ) | ||
|
|
||
| // Points define user-injected hook points. | ||
| type Points interface { | ||
| GasTarget(parent *types.Block) gas.Gas | ||
| SubSecondBlockTime(*types.Block) gas.Gas | ||
| BeforeBlock(params.Rules, *state.StateDB, *types.Block) error | ||
| AfterBlock(*state.StateDB, *types.Block, types.Receipts) | ||
StephenButtolph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // BeforeBlock is intended to be called before processing a block, with the gas | ||
| // target sourced from [Points]. | ||
| func BeforeBlock(pts Points, rules params.Rules, sdb *state.StateDB, b *blocks.Block, clock *gastime.Time) error { | ||
| clock.FastForwardTo( | ||
| b.BuildTime(), | ||
| pts.SubSecondBlockTime(b.EthBlock()), | ||
| ) | ||
| target := pts.GasTarget(b.ParentBlock().EthBlock()) | ||
| if err := clock.SetTarget(target); err != nil { | ||
| return fmt.Errorf("%T.SetTarget() before block: %w", clock, err) | ||
| } | ||
| return pts.BeforeBlock(rules, sdb, b.EthBlock()) | ||
| } | ||
|
|
||
| // AfterBlock is intended to be called after processing a block, with the gas | ||
| // sourced from [types.Block.GasUsed] or equivalent. | ||
| func AfterBlock(pts Points, sdb *state.StateDB, b *types.Block, clock *gastime.Time, used gas.Gas, rs types.Receipts) { | ||
| clock.Tick(used) | ||
| pts.AfterBlock(sdb, b, rs) | ||
| } | ||
|
|
||
| // MinimumGasConsumption MUST be used as the implementation for the respective | ||
| // method on [params.RulesHooks]. The concrete type implementing the hooks MUST | ||
| // propagate incoming and return arguments unchanged. | ||
| func MinimumGasConsumption(txLimit uint64) uint64 { | ||
| _ = (params.RulesHooks)(nil) // keep the import to allow [] doc links | ||
| return intmath.CeilDiv(txLimit, saeparams.Lambda) | ||
| } | ||
StephenButtolph marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| // Package hookstest provides a test double for SAE's [hook] package. | ||
| package hookstest | ||
|
|
||
| import ( | ||
| "github.com/ava-labs/avalanchego/vms/components/gas" | ||
| "github.com/ava-labs/libevm/core/state" | ||
| "github.com/ava-labs/libevm/core/types" | ||
| "github.com/ava-labs/libevm/params" | ||
|
|
||
| "github.com/ava-labs/strevm/hook" | ||
| ) | ||
|
|
||
| // Stub implements [hook.Points]. | ||
| type Stub struct { | ||
| Target gas.Gas | ||
| } | ||
|
|
||
| var _ hook.Points = (*Stub)(nil) | ||
|
|
||
| // GasTarget ignores its argument and always returns [Stub.Target]. | ||
| func (s *Stub) GasTarget(parent *types.Block) gas.Gas { | ||
| return s.Target | ||
| } | ||
|
|
||
| // SubSecondBlockTime time ignores its argument and always returns 0. | ||
| func (*Stub) SubSecondBlockTime(*types.Block) gas.Gas { | ||
| return 0 | ||
| } | ||
|
|
||
| // BeforeBlock is a no-op that always returns nil. | ||
| func (*Stub) BeforeBlock(params.Rules, *state.StateDB, *types.Block) error { | ||
| return nil | ||
| } | ||
|
|
||
| // AfterBlock is a no-op. | ||
| func (*Stub) AfterBlock(*state.StateDB, *types.Block, types.Receipts) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|
|
||
| // Package params declares [Streaming Asynchronous Execution] (SAE) parameters. | ||
| // | ||
| // [Streaming Asynchronous Execution]: https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/194-streaming-asynchronous-execution | ||
| package params | ||
|
|
||
| // Lambda is the denominator for computing the minimum gas consumed per | ||
| // transaction. For a transaction with gas limit `g`, the minimum consumption is | ||
| // ceil(g/Lambda). | ||
| const Lambda = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.