diff --git a/.gitignore b/.gitignore index 7619b963..f91d5cde 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,3 @@ seda.env # coverage files coverage.txt -/.run/debug existing.run.xml diff --git a/go.mod b/go.mod index 13edeb42..6d1c9080 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,6 @@ require ( github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 - github.com/tidwall/gjson v1.17.1 go.uber.org/mock v0.4.0 google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c google.golang.org/grpc v1.63.2 @@ -208,8 +207,6 @@ require ( github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect github.com/tidwall/btree v1.7.0 // indirect - github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/pretty v1.2.1 // indirect github.com/ulikunitz/xz v0.5.11 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect diff --git a/go.sum b/go.sum index e600de61..3bfc44e1 100644 --- a/go.sum +++ b/go.sum @@ -1079,13 +1079,6 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= -github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U= -github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= -github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= -github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= diff --git a/x/wasm-storage/keeper/filter.go b/x/wasm-storage/keeper/filter.go index 273bdce0..23300634 100644 --- a/x/wasm-storage/keeper/filter.go +++ b/x/wasm-storage/keeper/filter.go @@ -2,8 +2,6 @@ package keeper import ( "errors" - - "github.com/tidwall/gjson" ) const ( @@ -12,66 +10,6 @@ const ( filterStdDev byte = 0x02 ) -type ( - modeFilter struct { - Algo uint - JSONPath string - } - - //stdFilter struct { - // Algo uint - // JSONPath string - // MaxSigma uint64 - // NumberType uint8 - //} -) - -func FilterMode(jsonPath string, exitCodes []uint8, reveals [][]byte) ([]bool, bool) { - var ( - outliers []bool - consensus bool - nonZeroExitCode int - ) - - vals := make([]string, 0, len(reveals)) - for i, r := range reveals { - vals = append(vals, gjson.GetBytes(r, jsonPath).String()) - if exitCodes[i] != 0 { - nonZeroExitCode++ - } - } - outliers, consensus = calculate(vals) - - if consensus || nonZeroExitCode*3 > 2*len(reveals) { - return outliers, true - } - return outliers, false -} - -func calculate[T comparable](reveals []T) ([]bool, bool) { - freq := make(map[T]int, len(reveals)) - outliers := make([]bool, 0, len(reveals)) - var maxFreq int - - for _, r := range reveals { - freq[r]++ - if freq[r] > maxFreq { - maxFreq = freq[r] - } - } - - if maxFreq*3 < len(reveals)*2 { - outliers = make([]bool, len(reveals)) - return outliers, false - } - - for _, r := range reveals { - outliers = append(outliers, freq[r] != maxFreq) - } - - return outliers, true -} - // ApplyFilter processes filter of the type specified in the first byte of // tally inputs. It returns an outlier list, which is a boolean list where // true at index i means that the reveal at index i is an outlier, consensus @@ -91,24 +29,6 @@ func ApplyFilter(tallyInputs []byte, reveals []RevealBody) ([]bool, bool, error) case filterMode: // TODO: Reactivate mode filter - /* - var filter modeFilter - if err := rlp.DecodeBytes(tallyInputs, &filter); err != nil { - return nil, false, err - } - if filter.JSONPath == "" { - return nil, false, errors.New("empty JSON path") - } - - exitCodes := make([]uint8, len(reveals)) - revealData := make([][]byte, len(reveals)) - for i, r := range reveals { - exitCodes[i] = r.ExitCode - revealData[i] = r.Reveal - } - outliers, consensus := FilterMode(filter.JSONPath, exitCodes, revealData) - return outliers, consensus, nil - */ return nil, false, errors.New("filter type mode is not implemented") case filterStdDev: diff --git a/x/wasm-storage/keeper/filter_test.go b/x/wasm-storage/keeper/filter_test.go index 35fbc59e..7089b427 100644 --- a/x/wasm-storage/keeper/filter_test.go +++ b/x/wasm-storage/keeper/filter_test.go @@ -17,7 +17,7 @@ func TestOutliers_None(t *testing.T) { }{ { name: "None filter", - tallyInput: []byte{193, 128}, // filterProp{ Algo: 0} + tallyInput: []byte{0, 26, 129, 196}, // filterProp{ Algo: 0} want: []bool{false, false, false, false, false}, reveals: []keeper.RevealBody{ {}, @@ -36,7 +36,9 @@ func TestOutliers_None(t *testing.T) { require.ErrorIs(t, err, tt.wantErr) return } - require.Equal(t, got, tt.want) + + require.NoError(t, err) + require.Equal(t, tt.want, got) }) } } diff --git a/x/wasm-storage/keeper/msg_server_test.go b/x/wasm-storage/keeper/msg_server_test.go index 3711398e..fe5882a6 100644 --- a/x/wasm-storage/keeper/msg_server_test.go +++ b/x/wasm-storage/keeper/msg_server_test.go @@ -153,7 +153,7 @@ func (s *KeeperTestSuite) TestStoreOverlayWasm() { { name: "invalid authority", input: types.MsgStoreOverlayWasm{ - Sender: "cosmos16wfryel63g7axeamw68630wglalcnk3l0zuadc", + Sender: "seda1ucv5709wlf9jn84ynyjzyzeavwvurmdyxat26l", Wasm: regWasmZipped, WasmType: types.WasmTypeRelayer, },