Skip to content

Commit

Permalink
feat: pass additional env variables to tally vm
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Aug 27, 2024
1 parent 9f2a014 commit 3252df6
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 44 deletions.
12 changes: 10 additions & 2 deletions x/tally/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,16 @@ func (k Keeper) FilterAndTally(ctx sdk.Context, req types.Request) (tallyvm.VmRe
"arguments", args,
)
vmRes := tallyvm.ExecuteTallyVm(tallyWasm.Bytecode, args, map[string]string{
"VM_MODE": "tally",
"CONSENSUS": fmt.Sprintf("%v", consensus),
"VM_MODE": "tally",
"CONSENSUS": fmt.Sprintf("%v", consensus),
"DR_ID": req.ID,
"DR_INPUT": req.DrInputs,
"BINARY_ID": req.DrBinaryID,
"DR_REPLICATION_FACTOR": fmt.Sprintf("%v", req.ReplicationFactor),
"DR_GAS_PRICE": req.GasPrice,
"DR_GAS_LIMIT": req.GasLimit,
"DR_MEMO": req.Memo,
"DR_PAYBACK_ADDRESS": req.PaybackAddress,
})
return vmRes, consensus, nil
}
Expand Down
144 changes: 133 additions & 11 deletions x/tally/keeper/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/sedaprotocol/seda-wasm-vm/tallyvm"

"github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testdata"
"github.com/sedaprotocol/seda-chain/x/tally/keeper/testdata"
wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types"
)

Expand Down Expand Up @@ -66,25 +66,147 @@ func TestExecuteTally(t *testing.T) {
f := initFixture(t)
ctx := f.Context()

// NOTE: consensus_filter = "AQAAAAAAAAALcmVzdWx0LnRleHQ="
// represents mode filter with data path "result.text".
tests := []struct {
name string
resp []byte
wantErrStr []string
}{
{
name: "None filter - Tally 8ade60",
resp: []byte(`[{"consensus_filter":"AAEBAQE=","commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":1661661742461173125,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","replication_factor":3,"reveals":{"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{"exit_code":0,"gas_used":"10","reveal":"Ng==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{"exit_code":0,"gas_used":"10","reveal":"LQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{"exit_code":0,"gas_used":"10","reveal":"DQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"bXktdGFsbHktaW5wdXRz","version":"1.0.0"},{"consensus_filter":"AAEBAQE=","commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":9859593541233596221,"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f","memo":"","payback_address":"","replication_factor":1,"reveals":{"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{"exit_code":0,"gas_used":"10","reveal":"Yw==","salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"bXktdGFsbHktaW5wdXRz","version":"1.0.0"}]`),
wantErrStr: []string{"seda_common::msgs::data_requests::types::DataRequest; key:", "not found"},
},
{
name: "None filter - Tally f49da6",
resp: []byte(`[{"consensus_filter":"AAEBAQE=","commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":1661661742461173125,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","replication_factor":3,"reveals":{"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{"exit_code":0,"gas_used":"10","reveal":"Ng==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{"exit_code":0,"gas_used":"10","reveal":"LQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"},"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{"exit_code":0,"gas_used":"10","reveal":"DQ==","salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"bXktdGFsbHktaW5wdXRz","version":"1.0.0"},{"consensus_filter":"AAEBAQE=","commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":9859593541233596221,"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f","memo":"","payback_address":"","replication_factor":1,"reveals":{"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{"exit_code":0,"gas_used":"10","reveal":"Yw==","salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"}},"seda_payload":"","tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b","tally_inputs":"bXktdGFsbHktaW5wdXRz","version":"1.0.0"}]`),
name: "None filter",
resp: []byte(`[
{
"consensus_filter":"AAEBAQE=",
"commits":{},
"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf",
"dr_inputs":"",
"gas_limit":"20",
"gas_price":"10",
"height":1661661742461173125,
"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e",
"memo":"",
"payback_address":"",
"replication_factor":3,
"reveals":{
"1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":{
"exit_code":0,
"gas_used":"10",
"reveal":"Ng==",
"salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"
},
"1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":{
"exit_code":0,
"gas_used":"10",
"reveal":"LQ==",
"salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"
},
"421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":{
"exit_code":0,
"gas_used":"10",
"reveal":"DQ==",
"salt":"05952214b2ba3549a8d627c57d2d0dd1b0a2ce65c46e3b2f25c273464be8ba5f"
}
},
"seda_payload":"",
"tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b",
"tally_inputs":"bXktdGFsbHktaW5wdXRz",
"version":"1.0.0"
},
{
"consensus_filter":"AAEBAQE=",
"commits":{},
"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf",
"dr_inputs":"",
"gas_limit":"20",
"gas_price":"10",
"height":9859593541233596221,
"id":"d4e40f45fbf529134926acf529baeb6d4f37b5c380d7ab6b934833e7c00d725f",
"memo":"",
"payback_address":"",
"replication_factor":1,
"reveals":{
"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{
"exit_code":0,
"gas_used":"10",
"reveal":"Yw==",
"salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"
}
},
"seda_payload":"",
"tally_binary_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b",
"tally_inputs":"bXktdGFsbHktaW5wdXRz",
"version":"1.0.0"
}
]`),
wantErrStr: []string{"seda_common::msgs::data_requests::types::DataRequest; key:", "not found"},
},
{
name: "Mode filter",
// consensus_filter = "AQAAAAAAAAALcmVzdWx0LnRleHQ=" represents mode filter with data path "result.text".
resp: []byte(`[{"commits":{},"dr_binary_id":"9471d36add157cd7eaa32a42b5ddd091d5d5d396bf9ad67938a4fc40209df6cf","dr_inputs":"","gas_limit":"20","gas_price":"10","height":1661661742461173200,"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e","memo":"","payback_address":"","consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=","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":"20",
"gas_price":"10",
"height":1661661742461173200,
"id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e",
"memo":"mock_data_request_num_one",
"payback_address":"YrzimoSJXwpA7ju71AkhkirkDCU=",
"consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=",
"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":"5f3b31bff28c64a143119ee6389d62e38767672daace9c36db54fa2d18e9f391",
"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":"mock_data_request_num_two",
"payback_address":"YrzimoSJXwpA7ju71AkhkirkDCU=",
"consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=",
"replication_factor":1,
"reveals":{
"c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{
"exit_code":0,
"gas_used":"10",
"reveal":"eyJyZXN1bHQiOiB7InRleHQiOiAiQiIsICJudW1iZXIiOiAxMH19",
"salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf"
}
},
"seda_payload":"",
"tally_binary_id":"5f3b31bff28c64a143119ee6389d62e38767672daace9c36db54fa2d18e9f391",
"tally_inputs":"AAEBAQE=",
"version":"1.0.0"
}
]`),
wantErrStr: []string{"seda_common::msgs::data_requests::types::DataRequest; key:", "not found"},
},
}
Expand All @@ -98,7 +220,7 @@ func TestExecuteTally(t *testing.T) {
err := f.wasmStorageKeeper.DataRequestWasm.Set(ctx, tallyWasm.Hash, tallyWasm)
require.NoError(t, err)

tallyWasm = wasmstoragetypes.NewDataRequestWasm(testdata.SampleTallyWasm(), ctx.BlockTime(), ctx.BlockHeight(), 100)
tallyWasm = wasmstoragetypes.NewDataRequestWasm(testdata.SampleTallyWasm2(), ctx.BlockTime(), ctx.BlockHeight(), 100)
err = f.wasmStorageKeeper.DataRequestWasm.Set(ctx, tallyWasm.Hash, tallyWasm)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions x/tally/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ import (
stakingkeeper "github.com/sedaprotocol/seda-chain/x/staking/keeper"
"github.com/sedaprotocol/seda-chain/x/tally"
"github.com/sedaprotocol/seda-chain/x/tally/keeper"
"github.com/sedaprotocol/seda-chain/x/tally/keeper/testdata"
"github.com/sedaprotocol/seda-chain/x/tally/types"
wasmstorage "github.com/sedaprotocol/seda-chain/x/wasm-storage"
wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper"
"github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testdata"
"github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testutil"
wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types"
)
Expand Down Expand Up @@ -187,7 +187,7 @@ func initFixture(tb testing.TB) *fixture {

// Upload and instantiate the SEDA contract.
creator := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address())
codeID, _, err := contractKeeper.Create(ctx, creator, testdata.SedaContractWasm(), nil)
codeID, _, err := contractKeeper.Create(ctx, creator, testdata.CoreContractWasm(), nil)
require.NoError(tb, err)
require.Equal(tb, uint64(1), codeID)

Expand Down
20 changes: 15 additions & 5 deletions x/tally/keeper/testdata/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ import (
)

var (
//go:embed seda_contract.wasm
sedaContract []byte
//go:embed core_contract.wasm
coreContract []byte

//go:embed sample_tally.wasm
sampleTallyWasm []byte

//go:embed sample_tally_2.wasm
sampleTallyWasm2 []byte
)

func SedaContractWasm() []byte {
return sedaContract
func CoreContractWasm() []byte {
return coreContract
}

// SampleTallyWasm returns the sample tally wasm binary, whose Keccak256
// SampleTallyWasm returns a sample tally wasm binary whose Keccak256
// hash is 8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b.
func SampleTallyWasm() []byte {
return sampleTallyWasm
}

// SampleTallyWasm2 returns a tally wasm binary that prints all the
// tally VM environment variables.
// Hash: 5f3b31bff28c64a143119ee6389d62e38767672daace9c36db54fa2d18e9f391
func SampleTallyWasm2() []byte {
return sampleTallyWasm2
}
File renamed without changes.
Binary file added x/tally/keeper/testdata/sample_tally_2.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion x/tally/types/abci_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type DataResult struct {
ExitCode byte `json:"exit_code"`
GasUsed string `json:"gas_used"`
Result []byte `json:"result"`
PaybackAddress string `json:"payback_address"`
PaybackAddress string `json:"payback_address"` // base64-encoded string
SedaPayload string `json:"seda_payload"`
Consensus bool `json:"consensus"`
}
23 changes: 0 additions & 23 deletions x/wasm-storage/keeper/testdata/contracts.go

This file was deleted.

Binary file removed x/wasm-storage/keeper/testdata/data_requests.wasm
Binary file not shown.
Binary file removed x/wasm-storage/keeper/testdata/sample_tally.wasm
Binary file not shown.
Binary file removed x/wasm-storage/keeper/testdata/seda_contract.wasm
Binary file not shown.

0 comments on commit 3252df6

Please sign in to comment.