From 912ada33e469d3900442e5aa78e80bc66793753e Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Mon, 27 Feb 2023 17:51:47 -0600 Subject: [PATCH 1/3] [price-feeder] gracefully handle nil response for new provider (#617) --- oracle/price-feeder/oracle/provider/binance.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/coinbase.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/gate.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/huobi.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/kraken.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/mexc.go | 12 ++++++++++-- oracle/price-feeder/oracle/provider/okx.go | 12 ++++++++++-- 7 files changed, 70 insertions(+), 14 deletions(-) diff --git a/oracle/price-feeder/oracle/provider/binance.go b/oracle/price-feeder/oracle/provider/binance.go index 579085b031..0efe9da826 100644 --- a/oracle/price-feeder/oracle/provider/binance.go +++ b/oracle/price-feeder/oracle/provider/binance.go @@ -104,7 +104,11 @@ func NewBinanceProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to Binance websocket: %w", err) } @@ -366,7 +370,11 @@ func (p *BinanceProvider) reconnect() error { p.logger.Debug().Msg("reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error reconnect to binance websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/coinbase.go b/oracle/price-feeder/oracle/provider/coinbase.go index 84478136a6..01db4619c7 100644 --- a/oracle/price-feeder/oracle/provider/coinbase.go +++ b/oracle/price-feeder/oracle/provider/coinbase.go @@ -113,7 +113,11 @@ func NewCoinbaseProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to Coinbase websocket: %w", err) } @@ -486,7 +490,11 @@ func (p *CoinbaseProvider) reconnect() error { p.logger.Debug().Msg("reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error reconnecting to Coinbase websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/gate.go b/oracle/price-feeder/oracle/provider/gate.go index de49beb456..d388598dac 100644 --- a/oracle/price-feeder/oracle/provider/gate.go +++ b/oracle/price-feeder/oracle/provider/gate.go @@ -126,7 +126,11 @@ func NewGateProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to Gate websocket: %w", err) } @@ -551,7 +555,11 @@ func (p *GateProvider) reconnect() error { p.logger.Debug().Msg("reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error reconnecting to Gate websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/huobi.go b/oracle/price-feeder/oracle/provider/huobi.go index bcb632afb6..6a79655939 100644 --- a/oracle/price-feeder/oracle/provider/huobi.go +++ b/oracle/price-feeder/oracle/provider/huobi.go @@ -116,7 +116,11 @@ func NewHuobiProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to Huobi websocket: %w", err) } @@ -388,7 +392,11 @@ func (p *HuobiProvider) reconnect() error { p.logger.Debug().Msg("reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error reconnecting to Huobi websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/kraken.go b/oracle/price-feeder/oracle/provider/kraken.go index dfaf3c3fb7..f9a76ea03d 100644 --- a/oracle/price-feeder/oracle/provider/kraken.go +++ b/oracle/price-feeder/oracle/provider/kraken.go @@ -122,7 +122,11 @@ func NewKrakenProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to websocket: %w", err) } @@ -492,7 +496,11 @@ func (p *KrakenProvider) reconnect() error { p.logger.Debug().Msg("trying to reconnect") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error connecting to Kraken websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/mexc.go b/oracle/price-feeder/oracle/provider/mexc.go index 67618e61de..09c5fe78ff 100644 --- a/oracle/price-feeder/oracle/provider/mexc.go +++ b/oracle/price-feeder/oracle/provider/mexc.go @@ -123,7 +123,11 @@ func NewMexcProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to mexc websocket: %w", err) } @@ -396,7 +400,11 @@ func (p *MexcProvider) reconnect() error { p.logger.Debug().Msg("mexc: reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("mexc: error reconnect to mexc websocket: %w", err) } diff --git a/oracle/price-feeder/oracle/provider/okx.go b/oracle/price-feeder/oracle/provider/okx.go index cd8c441d6b..0c7e762f5e 100644 --- a/oracle/price-feeder/oracle/provider/okx.go +++ b/oracle/price-feeder/oracle/provider/okx.go @@ -124,7 +124,11 @@ func NewOkxProvider( } wsConn, response, err := websocket.DefaultDialer.Dial(wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return nil, fmt.Errorf("error connecting to Okx websocket: %w", err) } @@ -430,7 +434,11 @@ func (p *OkxProvider) reconnect() error { p.logger.Debug().Msg("reconnecting websocket") wsConn, response, err := websocket.DefaultDialer.Dial(p.wsURL.String(), nil) - defer response.Body.Close() + defer func() { + if response != nil { + response.Body.Close() + } + }() if err != nil { return fmt.Errorf("error reconnecting to Okx websocket: %w", err) } From e83d963ac84fad9894d0c8809721306a83d273e0 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Mon, 27 Feb 2023 23:24:30 -0600 Subject: [PATCH 2/3] [oracle] Move store operations outside of iterator (#619) --- x/oracle/keeper/keeper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x/oracle/keeper/keeper.go b/x/oracle/keeper/keeper.go index c1ba6e7067..ca5835a7a9 100755 --- a/x/oracle/keeper/keeper.go +++ b/x/oracle/keeper/keeper.go @@ -386,6 +386,7 @@ func (k Keeper) AddPriceSnapshot(ctx sdk.Context, snapshot types.PriceSnapshot) k.SetPriceSnapshot(ctx, snapshot) var lastOutOfRangeSnapshotTimestamp int64 = -1 + timestampsToDelete := []int64{} // we need to evict old snapshots (except for one that is out of range) k.IteratePriceSnapshots(ctx, func(snapshot types.PriceSnapshot) (stop bool) { if snapshot.SnapshotTimestamp+lookbackDuration >= ctx.BlockTime().Unix() { @@ -393,12 +394,15 @@ func (k Keeper) AddPriceSnapshot(ctx sdk.Context, snapshot types.PriceSnapshot) } // delete the previous out of range snapshot if lastOutOfRangeSnapshotTimestamp >= 0 { - k.DeletePriceSnapshot(ctx, lastOutOfRangeSnapshotTimestamp) + timestampsToDelete = append(timestampsToDelete, lastOutOfRangeSnapshotTimestamp) } // update last out of range snapshot lastOutOfRangeSnapshotTimestamp = snapshot.SnapshotTimestamp return false }) + for _, ts := range timestampsToDelete { + k.DeletePriceSnapshot(ctx, ts) + } } func (k Keeper) IteratePriceSnapshots(ctx sdk.Context, handler func(snapshot types.PriceSnapshot) (stop bool)) { From 61512d4647733728bd2b9d59d81be132e0d1878a Mon Sep 17 00:00:00 2001 From: codchen Date: Tue, 28 Feb 2023 04:39:21 -0800 Subject: [PATCH 3/3] Add params to guard Nitro fraud challenge (#600) --- go.mod | 12 +++--- go.sum | 20 +++++----- proto/nitro/params.proto | 3 ++ x/nitro/keeper/msg_server.go | 4 ++ x/nitro/keeper/msg_server_test.go | 10 ++++- x/nitro/keeper/params.go | 5 +++ x/nitro/types/errors.go | 1 + x/nitro/types/params.go | 17 ++++++++- x/nitro/types/params.pb.go | 63 ++++++++++++++++++++++++++----- 9 files changed, 107 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index b5d79342b2..08acd70058 100644 --- a/go.mod +++ b/go.mod @@ -36,8 +36,8 @@ require ( go.opentelemetry.io/otel/trace v1.9.0 golang.org/x/exp v0.0.0-20221031165847-c99f073a8326 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 - google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 - google.golang.org/grpc v1.51.0 + google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 + google.golang.org/grpc v1.53.0 google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 @@ -252,10 +252,10 @@ require ( golang.org/x/crypto v0.1.0 // indirect golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect golang.org/x/mod v0.6.0 // indirect - golang.org/x/net v0.3.0 // indirect - golang.org/x/sys v0.3.0 // indirect - golang.org/x/term v0.3.0 // indirect - golang.org/x/text v0.5.0 // indirect + golang.org/x/net v0.7.0 // indirect + golang.org/x/sys v0.5.0 // indirect + golang.org/x/term v0.5.0 // indirect + golang.org/x/text v0.7.0 // indirect golang.org/x/tools v0.2.0 // indirect gopkg.in/ini.v1 v1.66.6 // indirect honnef.co/go/tools v0.3.1 // indirect diff --git a/go.sum b/go.sum index 4558346831..37e7465027 100644 --- a/go.sum +++ b/go.sum @@ -1417,8 +1417,8 @@ golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.3.0 h1:VWL6FNY2bEEmsGVKabSlHu5Irp34xmMRoqb/9lF9lxk= -golang.org/x/net v0.3.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= +golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1559,13 +1559,13 @@ golang.org/x/sys v0.0.0-20220328115105-d36c6a25d886/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= -golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= +golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1575,8 +1575,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM= -golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1815,8 +1815,8 @@ google.golang.org/genproto v0.0.0-20220304144024-325a89244dc8/go.mod h1:kGP+zUP2 google.golang.org/genproto v0.0.0-20220310185008-1973136f34c6/go.mod h1:kGP+zUP2Ddo0ayMi4YuN7C3WZyJvGLZRh8Z5wnAqvEI= google.golang.org/genproto v0.0.0-20220324131243-acbaeb5b85eb/go.mod h1:hAL49I2IFola2sVEjAn7MEwsja0xp51I0tlGAf9hz4E= google.golang.org/genproto v0.0.0-20220407144326-9054f6ed7bac/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= -google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37 h1:jmIfw8+gSvXcZSgaFAGyInDXeWzUhvYH57G/5GKMn70= -google.golang.org/genproto v0.0.0-20221207170731-23e4bf6bdc37/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= +google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148 h1:muK+gVBJBfFb4SejshDBlN2/UgxCCOKH9Y34ljqEGOc= +google.golang.org/genproto v0.0.0-20230221151758-ace64dc21148/go.mod h1:3Dl5ZL0q0isWJt+FVcfpQyirqemEuLAK/iFvg1UP1Hw= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= diff --git a/proto/nitro/params.proto b/proto/nitro/params.proto index e81b01aa5d..f27c13fb84 100644 --- a/proto/nitro/params.proto +++ b/proto/nitro/params.proto @@ -9,4 +9,7 @@ message Params { repeated string whitelisted_tx_senders = 1 [ (gogoproto.jsontag) = "whitelisted_tx_senders" ]; + bool enabled = 2 [ + (gogoproto.jsontag) = "enabled" + ]; } diff --git a/x/nitro/keeper/msg_server.go b/x/nitro/keeper/msg_server.go index c92006aca8..9602ebcb6f 100644 --- a/x/nitro/keeper/msg_server.go +++ b/x/nitro/keeper/msg_server.go @@ -55,6 +55,10 @@ func (server msgServer) RecordTransactionData(goCtx context.Context, msg *types. func (server msgServer) SubmitFraudChallenge(goCtx context.Context, msg *types.MsgSubmitFraudChallenge) (*types.MsgSubmitFraudChallengeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) + if !server.IsFraudChallengeEnabled(ctx) { + return nil, types.ErrFraudChallengeDisabled + } + if len(msg.FraudStatePubKey) == 0 { return nil, types.ErrInvalidFraudStatePubkey } diff --git a/x/nitro/keeper/msg_server_test.go b/x/nitro/keeper/msg_server_test.go index 097037bd2e..d0649d9e11 100644 --- a/x/nitro/keeper/msg_server_test.go +++ b/x/nitro/keeper/msg_server_test.go @@ -71,7 +71,7 @@ func TestSubmitFraudChallenge(t *testing.T) { server := nitrokeeper.NewMsgServerImpl(*keeper) stateRoot, proof := createMockMerkleProof() // set state root with mock merkle root - keeper.SetParams(ctx, types.Params{WhitelistedTxSenders: []string{"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m"}}) + keeper.SetParams(ctx, types.Params{WhitelistedTxSenders: []string{"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m"}, Enabled: true}) _, err := server.RecordTransactionData(sdk.WrapSDKContext(ctx), &types.MsgRecordTransactionData{ Sender: "sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", Slot: 1, @@ -121,5 +121,13 @@ func TestSubmitFraudChallenge(t *testing.T) { }) require.Equal(t, err, types.ErrInvalidFraudStatePubkey) + keeper.SetParams(ctx, types.Params{WhitelistedTxSenders: []string{"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m"}}) + _, err = server.SubmitFraudChallenge(sdk.WrapSDKContext(ctx), &types.MsgSubmitFraudChallenge{ + StartSlot: 0, + EndSlot: 2, + FraudStatePubKey: "123", + MerkleProof: proof, + }) + require.Equal(t, err, types.ErrFraudChallengeDisabled) // TODO: add happy path with replayable account states } diff --git a/x/nitro/keeper/params.go b/x/nitro/keeper/params.go index 0da89a7d40..2576c4d6c5 100644 --- a/x/nitro/keeper/params.go +++ b/x/nitro/keeper/params.go @@ -29,3 +29,8 @@ func (k Keeper) IsTxSenderWhitelisted(ctx sdk.Context, addr string) bool { } return false } + +func (k Keeper) IsFraudChallengeEnabled(ctx sdk.Context) bool { + params := k.GetParams(ctx) + return params.Enabled +} diff --git a/x/nitro/types/errors.go b/x/nitro/types/errors.go index e94fde6d6a..2f3077a2a7 100644 --- a/x/nitro/types/errors.go +++ b/x/nitro/types/errors.go @@ -12,4 +12,5 @@ var ( ErrInvalidMerkleProof = sdkerrors.Register(ModuleName, 3, "Error invalid merkle proof") ErrInvalidAccountState = sdkerrors.Register(ModuleName, 4, "Error invalid provided account state") ErrInvalidFraudStatePubkey = sdkerrors.Register(ModuleName, 6, "Error invalid provided fraud state public key") + ErrFraudChallengeDisabled = sdkerrors.Register(ModuleName, 7, "Error fraud challenge is not enabled yet") ) diff --git a/x/nitro/types/params.go b/x/nitro/types/params.go index 59ad64f8f6..e6fb18f32e 100644 --- a/x/nitro/types/params.go +++ b/x/nitro/types/params.go @@ -10,6 +10,7 @@ import ( // Parameter store keys. var ( KeyWhitelistedTxSenders = []byte("WhitelistedTxSenders") + KeyEnabled = []byte("Enabled") ) // ParamTable for gamm module. @@ -17,9 +18,10 @@ func ParamKeyTable() paramtypes.KeyTable { return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) } -func NewParams(whitelistedTxSenders []string) Params { +func NewParams(whitelistedTxSenders []string, enabled bool) Params { return Params{ WhitelistedTxSenders: whitelistedTxSenders, + Enabled: enabled, } } @@ -27,6 +29,7 @@ func NewParams(whitelistedTxSenders []string) Params { func DefaultParams() Params { return Params{ WhitelistedTxSenders: []string{}, + Enabled: false, } } @@ -35,6 +38,9 @@ func (p Params) Validate() error { if err := validateWhitelistedTxSenders(p.WhitelistedTxSenders); err != nil { return err } + if err := validateEnabled(p.Enabled); err != nil { + return err + } return nil } @@ -43,6 +49,7 @@ func (p Params) Validate() error { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyWhitelistedTxSenders, &p.WhitelistedTxSenders, validateWhitelistedTxSenders), + paramtypes.NewParamSetPair(KeyEnabled, &p.Enabled, validateEnabled), } } @@ -60,3 +67,11 @@ func validateWhitelistedTxSenders(i interface{}) error { return nil } + +func validateEnabled(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + return nil +} diff --git a/x/nitro/types/params.pb.go b/x/nitro/types/params.pb.go index d4dfa2b106..2eb04a44a3 100644 --- a/x/nitro/types/params.pb.go +++ b/x/nitro/types/params.pb.go @@ -25,6 +25,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type Params struct { WhitelistedTxSenders []string `protobuf:"bytes,1,rep,name=whitelisted_tx_senders,json=whitelistedTxSenders,proto3" json:"whitelisted_tx_senders"` + Enabled bool `protobuf:"varint,2,opt,name=enabled,proto3" json:"enabled"` } func (m *Params) Reset() { *m = Params{} } @@ -67,6 +68,13 @@ func (m *Params) GetWhitelistedTxSenders() []string { return nil } +func (m *Params) GetEnabled() bool { + if m != nil { + return m.Enabled + } + return false +} + func init() { proto.RegisterType((*Params)(nil), "seiprotocol.seichain.nitro.Params") } @@ -74,20 +82,22 @@ func init() { func init() { proto.RegisterFile("nitro/params.proto", fileDescriptor_511e5e88523341bc) } var fileDescriptor_511e5e88523341bc = []byte{ - // 200 bytes of a gzipped FileDescriptorProto + // 228 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xca, 0xcb, 0x2c, 0x29, 0xca, 0xd7, 0x2f, 0x48, 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x2a, 0x4e, 0xcd, 0x04, 0xb3, 0x92, 0xf3, 0x73, 0xf4, 0x8a, 0x53, 0x33, 0x93, 0x33, 0x12, 0x33, 0xf3, 0xf4, 0xc0, 0x0a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x92, 0xfa, 0x20, 0x16, 0x44, - 0x87, 0x52, 0x14, 0x17, 0x5b, 0x00, 0xd8, 0x04, 0xa1, 0x00, 0x2e, 0xb1, 0xf2, 0x8c, 0xcc, 0x92, - 0xd4, 0x9c, 0xcc, 0xe2, 0x92, 0xd4, 0x94, 0xf8, 0x92, 0x8a, 0xf8, 0xe2, 0xd4, 0xbc, 0x94, 0xd4, - 0xa2, 0x62, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x4e, 0x27, 0xa9, 0x57, 0xf7, 0xe4, 0x71, 0xa8, 0x08, - 0x12, 0x41, 0x12, 0x0f, 0xa9, 0x08, 0x86, 0x88, 0x3a, 0x79, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, - 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, - 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x7e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, - 0x7e, 0x71, 0x6a, 0xa6, 0x2e, 0xcc, 0xcd, 0x60, 0x0e, 0xd8, 0xd1, 0xfa, 0x15, 0xfa, 0x10, 0xff, - 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x55, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, - 0xd4, 0xa1, 0xdd, 0x7e, 0xf5, 0x00, 0x00, 0x00, + 0x87, 0x52, 0x23, 0x23, 0x17, 0x5b, 0x00, 0xd8, 0x08, 0xa1, 0x00, 0x2e, 0xb1, 0xf2, 0x8c, 0xcc, + 0x92, 0xd4, 0x9c, 0xcc, 0xe2, 0x92, 0xd4, 0x94, 0xf8, 0x92, 0x8a, 0xf8, 0xe2, 0xd4, 0xbc, 0x94, + 0xd4, 0xa2, 0x62, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x4e, 0x27, 0xa9, 0x57, 0xf7, 0xe4, 0x71, 0xa8, + 0x08, 0x12, 0x41, 0x12, 0x0f, 0xa9, 0x08, 0x86, 0x88, 0x0a, 0xa9, 0x72, 0xb1, 0xa7, 0xe6, 0x25, + 0x26, 0xe5, 0xa4, 0xa6, 0x48, 0x30, 0x29, 0x30, 0x6a, 0x70, 0x38, 0x71, 0xbf, 0xba, 0x27, 0x0f, + 0x13, 0x0a, 0x82, 0x31, 0x9c, 0x3c, 0x4f, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, + 0x23, 0x39, 0xc6, 0x09, 0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, + 0x4a, 0x3f, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57, 0xbf, 0x38, 0x35, 0x53, + 0x17, 0xe6, 0x37, 0x30, 0x07, 0xec, 0x39, 0xfd, 0x0a, 0x7d, 0x48, 0x38, 0x94, 0x54, 0x16, 0xa4, + 0x16, 0x27, 0xb1, 0x81, 0x55, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xf2, 0xe6, 0x00, 0xb8, + 0x1d, 0x01, 0x00, 0x00, } func (m *Params) Marshal() (dAtA []byte, err error) { @@ -110,6 +120,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Enabled { + i-- + if m.Enabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } if len(m.WhitelistedTxSenders) > 0 { for iNdEx := len(m.WhitelistedTxSenders) - 1; iNdEx >= 0; iNdEx-- { i -= len(m.WhitelistedTxSenders[iNdEx]) @@ -145,6 +165,9 @@ func (m *Params) Size() (n int) { n += 1 + l + sovParams(uint64(l)) } } + if m.Enabled { + n += 2 + } return n } @@ -215,6 +238,26 @@ func (m *Params) Unmarshal(dAtA []byte) error { } m.WhitelistedTxSenders = append(m.WhitelistedTxSenders, string(dAtA[iNdEx:postIndex])) iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Enabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.Enabled = bool(v != 0) default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:])