From c9c4c2db2cc458be8144405594cdb82dc9f48fac Mon Sep 17 00:00:00 2001 From: Thomas van Dam Date: Tue, 17 Sep 2024 20:44:20 +0200 Subject: [PATCH 1/2] chore: upgrade tally vm to v1.2.0 This includes a new import for the VM as well as simple gas metering. --- go.mod | 2 +- go.sum | 4 ++-- x/tally/keeper/abci_test.go | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 5068859c..2c541f97 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/rakyll/statik v0.1.7 github.com/rs/zerolog v1.33.0 - github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.1.3 + github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.2.0 github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c github.com/spf13/cast v1.7.0 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 68ec140d..42f949b4 100644 --- a/go.sum +++ b/go.sum @@ -1015,8 +1015,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= github.com/sedaprotocol/rosetta-seda v0.0.0-20240427181737-e1d7563b2529 h1:VbJcd022MkoohRyAfktHnN99Brt/4eJr01mdLqPhGaE= github.com/sedaprotocol/rosetta-seda v0.0.0-20240427181737-e1d7563b2529/go.mod h1:GdlDqGJN2g55PHiwYJs2bQMlL0rdlQQbauK4dcrOI6w= -github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.1.3 h1:1y88DHfjQk6MERSzU/N6csBmx0XTClyVDzw2ZAwdJxs= -github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.1.3/go.mod h1:AaX9uRy6qD2q+o1SapTRnGUe9HHZWTmBN2BVNAptq3U= +github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.2.0 h1:Hv7Ox1F2bhdZYDjjRGgAwXDy4/U80PolpWR8YolA2g4= +github.com/sedaprotocol/seda-wasm-vm/tallyvm v1.2.0/go.mod h1:AaX9uRy6qD2q+o1SapTRnGUe9HHZWTmBN2BVNAptq3U= github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c h1:PbSn7HpWeox6lqBu6Ba6YZS3On3euwn1BPz/egsnEgA= github.com/sedaprotocol/vrf-go v0.0.0-20231211075603-e5a17bb0b87c/go.mod h1:DEIXHk41VUzOMVbZnIApssPXtZ+2zrETDP7kJjGc1RM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= diff --git a/x/tally/keeper/abci_test.go b/x/tally/keeper/abci_test.go index 5e177a65..764b6048 100644 --- a/x/tally/keeper/abci_test.go +++ b/x/tally/keeper/abci_test.go @@ -31,7 +31,7 @@ func TestTallyVM(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":1661661742461173125, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", @@ -72,7 +72,7 @@ func TestTallyVM(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":1661661742461173125, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", @@ -113,7 +113,7 @@ func TestTallyVM(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":9859593541233596221, "id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f", @@ -185,7 +185,7 @@ func TestTallyVM_EnvVars(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":1661661742461173200, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", @@ -252,7 +252,7 @@ func TestExecuteTally(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":1661661742461173125, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", @@ -289,7 +289,7 @@ func TestExecuteTally(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":9859593541233596221, "id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f", @@ -319,7 +319,7 @@ func TestExecuteTally(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":1661661742461173200, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", @@ -356,7 +356,7 @@ func TestExecuteTally(t *testing.T) { "commits":{}, "dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf", "dr_inputs":"", - "gas_limit":"20", + "gas_limit":"5000000000", "gas_price":"10", "height":9859593541233596000, "id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f", @@ -419,7 +419,7 @@ func TestEndBlock(t *testing.T) { }{ { name: "Invalid fetch format (gas limit)", - resp: []byte(`[{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":10,"gas_price":"10","height":1661661742461173200,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","consensus_filter":"A","replication_factor":3,"reveals":{"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQSIsICJudW1iZXIiOiAxMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQSIsICJudW1iZXIiOiAyMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQiIsICJudW1iZXIiOiAxMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"AAEBAQE=","version":"1.0.0"},{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":9859593541233596000,"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f","memo":"","payback_address":"","consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=","replication_factor":1,"reveals":{"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQiIsICJudW1iZXIiOiAxMH19","salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"AAEBAQE=","version":"1.0.0"}]`), + resp: []byte(`[{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":10,"gas_price":"10","height":1661661742461173200,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","consensus_filter":"A","replication_factor":3,"reveals":{"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQSIsICJudW1iZXIiOiAxMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQSIsICJudW1iZXIiOiAyMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQiIsICJudW1iZXIiOiAxMH19","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"AAEBAQE=","version":"1.0.0"},{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"5000000000","gas_price":"10","height":9859593541233596000,"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f","memo":"","payback_address":"","consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=","replication_factor":1,"reveals":{"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{"exit_code":0,"gas_used":"10","reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQiIsICJudW1iZXIiOiAxMH19","salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"AAEBAQE=","version":"1.0.0"}]`), expErrLog: []string{"ERR", "json: cannot unmarshal number into Go struct field Request.gas_limit of type string"}, }, } From 3293a2ef97754859d2c4962315824ae79ec305d4 Mon Sep 17 00:00:00 2001 From: Thomas van Dam Date: Wed, 18 Sep 2024 10:34:06 +0200 Subject: [PATCH 2/2] chore: update golangci to v1.61.0 Also fix the new issues identified by the update. --- Makefile | 2 +- x/randomness/keeper/abci.go | 16 ++++++++++------ x/tally/keeper/abci.go | 5 +++-- x/tally/types/filters.go | 1 - 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 513bd8c7..4cc3466d 100644 --- a/Makefile +++ b/Makefile @@ -146,7 +146,7 @@ fmt: ### Linting ### ############################################################################### -golangci_version=v1.60.3 +golangci_version=v1.61.0 lint-install: @echo "--> Installing golangci-lint $(golangci_version)" diff --git a/x/randomness/keeper/abci.go b/x/randomness/keeper/abci.go index 66dc954a..5bed5d07 100644 --- a/x/randomness/keeper/abci.go +++ b/x/randomness/keeper/abci.go @@ -50,6 +50,7 @@ func (h *ProposalHandler) PrepareProposalHandler( var maxBlockGas uint64 if b := ctx.ConsensusParams().Block; b != nil { + //nolint:gosec // G115: We should always have a gas limit for blocks. maxBlockGas = uint64(b.MaxGas) } @@ -93,7 +94,9 @@ func (h *ProposalHandler) PrepareProposalHandler( return nil, err } - stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, newSeedTx, newSeedTxBz) + //nolint:gosec // G115: We should always have a bytes limit for transactions + maxTxBytes := uint64(req.MaxTxBytes) + stop := h.txSelector.SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, newSeedTx, newSeedTxBz) if stop { return nil, types.ErrNewSeedTxNotIncluded } @@ -111,7 +114,7 @@ func (h *ProposalHandler) PrepareProposalHandler( continue } - stop := h.txSelector.SelectTxForProposal(ctx, uint64(req.MaxTxBytes), maxBlockGas, tx, txBz) + stop := h.txSelector.SelectTxForProposal(ctx, maxTxBytes, maxBlockGas, tx, txBz) if stop { break } @@ -130,9 +133,10 @@ func (h *ProposalHandler) ProcessProposalHandler( ) sdk.ProcessProposalHandler { return func(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) { var totalTxGas uint64 - var maxBlockGas int64 + var maxBlockGas uint64 if b := ctx.ConsensusParams().Block; b != nil { - maxBlockGas = b.MaxGas + //nolint:gosec // G115: We should always have a gas limit for blocks. + maxBlockGas = uint64(b.MaxGas) } // process the NewSeed tx @@ -147,7 +151,7 @@ func (h *ProposalHandler) ProcessProposalHandler( totalTxGas += gasTx.GetGas() } - if totalTxGas > uint64(maxBlockGas) { + if totalTxGas > maxBlockGas { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } } @@ -216,7 +220,7 @@ func (h *ProposalHandler) ProcessProposalHandler( totalTxGas += gasTx.GetGas() } - if totalTxGas > uint64(maxBlockGas) { + if totalTxGas > maxBlockGas { return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, err } } diff --git a/x/tally/keeper/abci.go b/x/tally/keeper/abci.go index 413c5296..02c7a039 100644 --- a/x/tally/keeper/abci.go +++ b/x/tally/keeper/abci.go @@ -77,8 +77,9 @@ func (k Keeper) ProcessTallies(ctx sdk.Context) error { sudoMsg := types.Sudo{ ID: req.ID, Result: types.DataResult{ - Version: req.Version, - ID: req.ID, + Version: req.Version, + ID: req.ID, + //nolint:gosec // G115: We shouldn't get negative block heights anwyay... BlockHeight: uint64(ctx.BlockHeight()), GasUsed: "0", // TODO PaybackAddress: req.PaybackAddress, diff --git a/x/tally/types/filters.go b/x/tally/types/filters.go index db922ee4..d68d04c3 100644 --- a/x/tally/types/filters.go +++ b/x/tally/types/filters.go @@ -3,7 +3,6 @@ package types import ( "bytes" "encoding/binary" - "slices" "golang.org/x/exp/constraints"