Skip to content

feat: canoto tags for gas.State #3982

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

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go 1.23.9
require (
github.com/DataDog/zstd v1.5.2
github.com/NYTimes/gziphandler v1.1.1
github.com/StephenButtolph/canoto v0.15.0
github.com/StephenButtolph/canoto v0.17.0
github.com/antithesishq/antithesis-sdk-go v0.3.8
github.com/ava-labs/coreth v0.15.1-rc.0.0.20250530184801-28421010abae
github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/StephenButtolph/canoto v0.15.0 h1:3iGdyTSQZ7/y09WaJCe0O/HIi53ZyTrnmVzfCqt64mM=
github.com/StephenButtolph/canoto v0.15.0/go.mod h1:IcnAHC6nJUfQFVR9y60ko2ecUqqHHSB6UwI9NnBFZnE=
github.com/StephenButtolph/canoto v0.17.0 h1:Ssih5oQNUoJJsoq6jmwoOamZN0KOePerZsmZN7rVCUM=
github.com/StephenButtolph/canoto v0.17.0/go.mod h1:IcnAHC6nJUfQFVR9y60ko2ecUqqHHSB6UwI9NnBFZnE=
github.com/VictoriaMetrics/fastcache v1.12.1 h1:i0mICQuojGDL3KblA7wUNlY5lOK6a4bwt3uRKnkZU40=
github.com/VictoriaMetrics/fastcache v1.12.1/go.mod h1:tX04vaqcNoQeGLD+ra5pU5sWkuxnzWhEzLwhP9w653o=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
Expand Down
8 changes: 4 additions & 4 deletions snow/engine/snowman/block/block_context_vm.canoto.go

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

2 changes: 1 addition & 1 deletion snow/engine/snowman/block/block_context_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Context struct {
// against the P-chain's state, this context is undefined for those blocks.
PChainHeight uint64 `canoto:"uint,1" json:"pChainHeight"`

canotoData canotoData_Context
canotoData canotoData_Context `canoto:"nocopy"` //nolint:revive // Tag on unexported field required by canoto
}

// BuildBlockWithContextChainVM defines the interface a ChainVM can optionally
Expand Down
206 changes: 206 additions & 0 deletions vms/components/gas/state.canoto.go

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

8 changes: 6 additions & 2 deletions vms/components/gas/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import (
safemath "github.com/ava-labs/avalanchego/utils/math"
)

//go:generate go run github.com/StephenButtolph/canoto/canoto $GOFILE

var ErrInsufficientCapacity = errors.New("insufficient capacity")

type State struct {
Capacity Gas `serialize:"true" json:"capacity"`
Excess Gas `serialize:"true" json:"excess"`
Capacity Gas `serialize:"true" canoto:"uint,1" json:"capacity"`
Excess Gas `serialize:"true" canoto:"uint,2" json:"excess"`

canotoData canotoData_State
}

// AdvanceTime adds maxPerSecond to capacity and subtracts targetPerSecond
Expand Down
10 changes: 10 additions & 0 deletions vms/components/gas/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@ func Test_State_ConsumeGas(t *testing.T) {
})
}
}

func TestStateCanoto(t *testing.T) {
in := State{
Capacity: 42,
Excess: 43,
}
var got State
require.NoError(t, got.UnmarshalCanoto(in.MarshalCanoto()))
require.Equal(t, in, got)
}
Loading