diff --git a/.github/workflows/interchaintest.yml b/.github/workflows/interchaintest.yml index 1fc5a229..7e794256 100644 --- a/.github/workflows/interchaintest.yml +++ b/.github/workflows/interchaintest.yml @@ -4,7 +4,7 @@ on: pull_request: env: - GO_VERSION: "1.22.11" + GO_VERSION: "1.23.5" TAR_PATH: /tmp/seda-docker-image.tar IMAGE_NAME: sedad-e2e diff --git a/app/ante_test.go b/app/ante_test.go index 3b1ded2b..589da412 100644 --- a/app/ante_test.go +++ b/app/ante_test.go @@ -68,7 +68,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmtypes.MsgExecuteContract{ @@ -86,13 +86,13 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof2", 20202), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof2"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, }, @@ -104,7 +104,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmtypes.MsgExecuteContract{ @@ -133,13 +133,13 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id_2", "commitment", "public_key", "proof", 10101), + Msg: testutil.CommitMsg("dr_id_2", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, }, @@ -151,7 +151,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmstoragetypes.MsgStoreOracleProgram{ @@ -162,7 +162,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id_2", "commitment", "public_key", "proof", 10101), + Msg: testutil.CommitMsg("dr_id_2", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, }, @@ -174,7 +174,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, &wasmtypes.MsgExecuteContract{ @@ -218,7 +218,7 @@ func TestCommitRevealDecorator_AnteHandle(t *testing.T) { &wasmtypes.MsgExecuteContract{ Sender: sender.String(), Contract: coreContractAddr.String(), - Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof", 19990), + Msg: testutil.CommitMsg("dr_id", "commitment", "public_key", "proof"), Funds: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), }, }, diff --git a/app/app.go b/app/app.go index 78dffe8e..efc7f49e 100644 --- a/app/app.go +++ b/app/app.go @@ -15,8 +15,8 @@ import ( tmproto "github.com/cometbft/cometbft/proto/tendermint/types" wasmapp "github.com/CosmWasm/wasmd/app" - wasm "github.com/CosmWasm/wasmd/x/wasm" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + sdkwasm "github.com/CosmWasm/wasmd/x/wasm" + sdkwasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" dbm "github.com/cosmos/cosmos-db" @@ -142,6 +142,9 @@ import ( "github.com/sedaprotocol/seda-chain/x/batching" batchingkeeper "github.com/sedaprotocol/seda-chain/x/batching/keeper" batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" + "github.com/sedaprotocol/seda-chain/x/core" + corekeeper "github.com/sedaprotocol/seda-chain/x/core/keeper" + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" dataproxy "github.com/sedaprotocol/seda-chain/x/data-proxy" dataproxykeeper "github.com/sedaprotocol/seda-chain/x/data-proxy/keeper" dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" @@ -151,11 +154,9 @@ import ( "github.com/sedaprotocol/seda-chain/x/slashing" "github.com/sedaprotocol/seda-chain/x/staking" stakingkeeper "github.com/sedaprotocol/seda-chain/x/staking/keeper" - "github.com/sedaprotocol/seda-chain/x/tally" - tallykeeper "github.com/sedaprotocol/seda-chain/x/tally/keeper" - tallytypes "github.com/sedaprotocol/seda-chain/x/tally/types" "github.com/sedaprotocol/seda-chain/x/vesting" vestingtypes "github.com/sedaprotocol/seda-chain/x/vesting/types" + "github.com/sedaprotocol/seda-chain/x/wasm" wasmstorage "github.com/sedaprotocol/seda-chain/x/wasm-storage" wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" @@ -190,7 +191,7 @@ var ( consensus.AppModuleBasic{}, circuit.AppModuleBasic{}, capability.AppModuleBasic{}, - wasm.AppModuleBasic{}, + sdkwasm.AppModuleBasic{}, ibc.AppModuleBasic{}, ibctm.AppModuleBasic{}, ibcfee.AppModuleBasic{}, @@ -200,9 +201,9 @@ var ( crisis.AppModuleBasic{}, packetforward.AppModuleBasic{}, wasmstorage.AppModuleBasic{}, - tally.AppModuleBasic{}, dataproxy.AppModuleBasic{}, batching.AppModuleBasic{}, + core.AppModuleBasic{}, ) // module account permissions @@ -218,6 +219,7 @@ var ( icatypes.ModuleName: nil, wasmtypes.ModuleName: {authtypes.Burner}, dataproxytypes.ModuleName: {authtypes.Burner}, + coretypes.ModuleName: {authtypes.Burner}, } ) @@ -324,7 +326,7 @@ func NewApp( capabilitytypes.StoreKey, ibcexported.StoreKey, ibctransfertypes.StoreKey, ibcfeetypes.StoreKey, wasmtypes.StoreKey, icahosttypes.StoreKey, icacontrollertypes.StoreKey, packetforwardtypes.StoreKey, crisistypes.StoreKey, wasmstoragetypes.StoreKey, dataproxytypes.StoreKey, pubkeytypes.StoreKey, - batchingtypes.StoreKey, tallytypes.StoreKey, + batchingtypes.StoreKey, coretypes.StoreKey, ) memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -575,14 +577,14 @@ func NewApp( app.EvidenceKeeper = *evidenceKeeper wasmDir := filepath.Join(homePath, "wasm") - wasmConfig, err := wasm.ReadWasmConfig(appOpts) + wasmConfig, err := sdkwasm.ReadWasmConfig(appOpts) if err != nil { panic(fmt.Sprintf("error while reading wasm config: %s", err)) } - var wasmOpts []wasmkeeper.Option + var wasmOpts []sdkwasmkeeper.Option - app.WasmKeeper = wasmkeeper.NewKeeper( + sdkWasmKeeper := sdkwasmkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), app.AccountKeeper, @@ -632,7 +634,13 @@ func NewApp( wasmtypes.MaxWasmSize = int(val) // default 819200 (800 * 1024) } - app.WasmContractKeeper = wasmkeeper.NewDefaultPermissionKeeper(&app.WasmKeeper) + app.WasmKeeper = wasm.NewKeeper( + &sdkWasmKeeper, + app.StakingKeeper, + appCodec, + app.MsgServiceRouter(), + ) + app.WasmContractKeeper = sdkwasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper) app.WasmStorageKeeper = *wasmstoragekeeper.NewKeeper( appCodec, @@ -645,6 +653,8 @@ func NewApp( app.WasmContractKeeper, ) + app.WasmKeeper.SetWasmStorageKeeper(app.WasmStorageKeeper) + app.PubKeyKeeper = pubkeykeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[pubkeytypes.StoreKey]), @@ -674,15 +684,17 @@ func NewApp( authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), ) - app.TallyKeeper = tallykeeper.NewKeeper( + app.CoreKeeper = corekeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[tallytypes.StoreKey]), + runtime.NewKVStoreService(keys[coretypes.StoreKey]), app.WasmStorageKeeper, app.BatchingKeeper, app.DataProxyKeeper, + app.StakingKeeper, + app.BankKeeper, app.WasmContractKeeper, app.WasmKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), // TODO: subject to change ) // Create evidence router, add batching evidence route, seal it, and set it in the keeper. @@ -736,7 +748,7 @@ func NewApp( /* WASM STACK */ /* =================================================== */ var wasmStack ibcporttypes.IBCModule - wasmStack = wasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) + wasmStack = sdkwasm.NewIBCHandler(app.WasmKeeper, app.IBCKeeper.ChannelKeeper, app.IBCFeeKeeper) wasmStack = ibcfee.NewIBCMiddleware(wasmStack, app.IBCFeeKeeper) /* =================================================== */ @@ -794,7 +806,7 @@ func NewApp( consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), circuit.NewAppModule(appCodec, app.CircuitKeeper), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), - wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), nil), + wasm.NewAppModule(appCodec, app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), nil), ibc.NewAppModule(app.IBCKeeper), ibcfee.NewAppModule(app.IBCFeeKeeper), transfer.NewAppModule(app.TransferKeeper), @@ -802,10 +814,10 @@ func NewApp( ibctm.AppModule{}, packetforward.NewAppModule(app.PacketForwardKeeper, nil), wasmstorage.NewAppModule(appCodec, app.WasmStorageKeeper), - tally.NewAppModule(appCodec, app.TallyKeeper), dataproxy.NewAppModule(appCodec, app.DataProxyKeeper), pubkey.NewAppModule(appCodec, app.PubKeyKeeper), batching.NewAppModule(appCodec, app.BatchingKeeper), + core.NewAppModule(appCodec, app.CoreKeeper), crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, nil), // always be last to make sure that it checks for all invariants and not only part of them ) @@ -861,7 +873,7 @@ func NewApp( packetforwardtypes.ModuleName, // custom modules wasmstoragetypes.ModuleName, - tallytypes.ModuleName, + coretypes.ModuleName, dataproxytypes.ModuleName, pubkeytypes.ModuleName, batchingtypes.ModuleName, @@ -894,7 +906,7 @@ func NewApp( packetforwardtypes.ModuleName, // custom modules wasmstoragetypes.ModuleName, - tallytypes.ModuleName, + coretypes.ModuleName, dataproxytypes.ModuleName, pubkeytypes.ModuleName, batchingtypes.ModuleName, @@ -934,7 +946,7 @@ func NewApp( packetforwardtypes.ModuleName, // custom modules (except pubkey) wasmstoragetypes.ModuleName, - tallytypes.ModuleName, + coretypes.ModuleName, dataproxytypes.ModuleName, batchingtypes.ModuleName, } @@ -950,7 +962,8 @@ func NewApp( if err != nil { panic(err) } - app.setupUpgrades() + // TODO Re-enable upgrades + // app.setupUpgrades() autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() @@ -983,7 +996,7 @@ func NewApp( }, IBCKeeper: app.IBCKeeper, WasmConfig: &wasmConfig, - WasmKeeper: &app.WasmKeeper, + WasmKeeper: app.WasmKeeper.Keeper, TXCounterStoreService: runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), CircuitKeeper: &app.CircuitKeeper, }, @@ -1050,7 +1063,7 @@ func NewApp( if manager := app.SnapshotManager(); manager != nil { err = manager.RegisterExtensions( - wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper), + sdkwasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), app.WasmKeeper.Keeper), ) if err != nil { panic("failed to register snapshot extension: " + err.Error()) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 8d76329c..0ba8937f 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -1,7 +1,6 @@ package keepers import ( - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" @@ -29,10 +28,11 @@ import ( slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" batchingkeeper "github.com/sedaprotocol/seda-chain/x/batching/keeper" + corekeeper "github.com/sedaprotocol/seda-chain/x/core/keeper" dataproxykeeper "github.com/sedaprotocol/seda-chain/x/data-proxy/keeper" pubkeykeeper "github.com/sedaprotocol/seda-chain/x/pubkey/keeper" stakingkeeper "github.com/sedaprotocol/seda-chain/x/staking/keeper" - tallykeeper "github.com/sedaprotocol/seda-chain/x/tally/keeper" + "github.com/sedaprotocol/seda-chain/x/wasm" wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper" ) @@ -58,7 +58,7 @@ type AppKeepers struct { IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly ICAHostKeeper icahostkeeper.Keeper TransferKeeper ibctransferkeeper.Keeper - WasmKeeper wasmkeeper.Keeper + WasmKeeper *wasm.Keeper IBCFeeKeeper ibcfeekeeper.Keeper ICAControllerKeeper icacontrollerkeeper.Keeper PacketForwardKeeper *packetforwardkeeper.Keeper @@ -75,7 +75,7 @@ type AppKeepers struct { // SEDA modules keepers WasmStorageKeeper wasmstoragekeeper.Keeper - TallyKeeper tallykeeper.Keeper + CoreKeeper corekeeper.Keeper DataProxyKeeper dataproxykeeper.Keeper PubKeyKeeper *pubkeykeeper.Keeper BatchingKeeper batchingkeeper.Keeper diff --git a/app/query.pb.go b/app/query.pb.go index 4150bcfd..598597ff 100644 --- a/app/query.pb.go +++ b/app/query.pb.go @@ -129,7 +129,7 @@ type SignerKey struct { Index uint32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` // IndexName is the name of the SEDA key. IndexName string `protobuf:"bytes,2,opt,name=index_name,json=indexName,proto3" json:"index_name,omitempty"` - // IsActive indicates whether the given SEDA key index is active. + // IsProvingSchemeActive indicates whether the given SEDA key index is active. IsProvingSchemeActive bool `protobuf:"varint,3,opt,name=is_proving_scheme_active,json=isProvingSchemeActive,proto3" json:"is_proving_scheme_active,omitempty"` // PublicKey is the hex-encoded public key of the key loaded in // the SEDA signer. diff --git a/app/upgrades.go b/app/upgrades.go deleted file mode 100644 index ec735fe1..00000000 --- a/app/upgrades.go +++ /dev/null @@ -1,68 +0,0 @@ -package app - -import ( - "fmt" - - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/sedaprotocol/seda-chain/app/upgrades" - v017 "github.com/sedaprotocol/seda-chain/app/upgrades/mainnet/v0.1.7" - v018 "github.com/sedaprotocol/seda-chain/app/upgrades/mainnet/v0.1.8" - v019 "github.com/sedaprotocol/seda-chain/app/upgrades/mainnet/v0.1.9" - v1 "github.com/sedaprotocol/seda-chain/app/upgrades/mainnet/v1" - v1rc4 "github.com/sedaprotocol/seda-chain/app/upgrades/testnet/v1.0.0-rc.4" - v1rc6 "github.com/sedaprotocol/seda-chain/app/upgrades/testnet/v1.0.0-rc.6" -) - -// Upgrades is a list of currently supported upgrades. -var Upgrades = []upgrades.Upgrade{ - v1rc4.Upgrade, - v1rc6.Upgrade, - v1.Upgrade, - v017.Upgrade, - v018.Upgrade, - v019.Upgrade, -} - -func (app *App) setupUpgrades() { - app.setUpgradeHandlers() - app.setUpgradeStoreLoaders() -} - -func (app *App) setUpgradeHandlers() { - keepers := app.AppKeepers - - // Register upgrade handlers. - for _, upgrade := range Upgrades { - app.UpgradeKeeper.SetUpgradeHandler( - upgrade.UpgradeName, - upgrade.CreateUpgradeHandler( - app.mm, - app.configurator, - &keepers, - ), - ) - } -} - -func (app *App) setUpgradeStoreLoaders() { - upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() - if err != nil { - panic(fmt.Sprintf("failed to read upgrade info from disk %s", err)) - } - - // Add new modules here when needed. - - if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - return - } - - // Register store loader for current upgrade. - for _, upgrade := range Upgrades { - if upgradeInfo.Name == upgrade.UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := upgrade.StoreUpgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) - break - } - } -} diff --git a/app/upgrades/mainnet/v0.1.7/constants.go b/app/upgrades/mainnet/v0.1.7/constants.go deleted file mode 100644 index 1d4ed8b7..00000000 --- a/app/upgrades/mainnet/v0.1.7/constants.go +++ /dev/null @@ -1,43 +0,0 @@ -package v1 - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" -) - -const ( - UpgradeName = "v0.1.7" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - // double check these - Added: []string{}, - Deleted: []string{}, - }, -} - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - _ *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Add additional upgrade logic when needed - - /* - * migrations are run in module name alphabetical - * ascending order, except x/auth which is run last - */ - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/app/upgrades/mainnet/v0.1.8/constants.go b/app/upgrades/mainnet/v0.1.8/constants.go deleted file mode 100644 index 7a98d121..00000000 --- a/app/upgrades/mainnet/v0.1.8/constants.go +++ /dev/null @@ -1,43 +0,0 @@ -package v1 - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" -) - -const ( - UpgradeName = "v0.1.8" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - // double check these - Added: []string{}, - Deleted: []string{}, - }, -} - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - _ *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Add additional upgrade logic when needed - - /* - * migrations are run in module name alphabetical - * ascending order, except x/auth which is run last - */ - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/app/upgrades/mainnet/v0.1.9/constants.go b/app/upgrades/mainnet/v0.1.9/constants.go deleted file mode 100644 index 91f9d125..00000000 --- a/app/upgrades/mainnet/v0.1.9/constants.go +++ /dev/null @@ -1,40 +0,0 @@ -package v1 - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" -) - -const ( - UpgradeName = "v0.1.9" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{}, - Deleted: []string{}, - }, -} - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - _ *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - /* - * migrations are run in module name alphabetical - * ascending order, except x/auth which is run last - */ - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/app/upgrades/mainnet/v1/constants.go b/app/upgrades/mainnet/v1/constants.go deleted file mode 100644 index 24c137dc..00000000 --- a/app/upgrades/mainnet/v1/constants.go +++ /dev/null @@ -1,93 +0,0 @@ -package v1 - -import ( - "context" - _ "embed" - "fmt" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" - batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" - dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" - pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" - tallytypes "github.com/sedaprotocol/seda-chain/x/tally/types" - wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" -) - -const ( - UpgradeName = "v1.0.0" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{wasmstoragetypes.StoreKey, batchingtypes.StoreKey, tallytypes.StoreKey, dataproxytypes.StoreKey, pubkeytypes.StoreKey}, - Deleted: []string{}, - }, -} - -//go:embed core_contract_d482138dc00ff9767e09e96fea92fc5bf13f948d.wasm -var wasmCode []byte - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - keepers *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(context context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - ctx := sdk.UnwrapSDKContext(context) - - // Run module migrations. - migrations, err := mm.RunMigrations(ctx, configurator, fromVM) - if err != nil { - return nil, err - } - - // Additional upgrade logic for instantiating the Core Contract. - securityGroupAddr := "seda1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzs026662" - adminAddr, err := sdk.AccAddressFromBech32(securityGroupAddr) - if err != nil { - return nil, err - } - - codeID, _, err := keepers.WasmContractKeeper.Create(ctx, adminAddr, wasmCode, nil) - if err != nil { - return nil, err - } - contractAddr, _, err := keepers.WasmContractKeeper.Instantiate( - ctx, codeID, adminAddr, adminAddr, - []byte(fmt.Sprintf(`{ - "token":"aseda", - "owner": "%s", - "chain_id":"%s" - }`, securityGroupAddr, ctx.ChainID())), - "label", nil) - if err != nil { - return nil, err - } - err = keepers.WasmStorageKeeper.CoreContractRegistry.Set(ctx, contractAddr.String()) - if err != nil { - return nil, err - } - - // Enable vote extension at current height. - consensusParams, err := keepers.ConsensusParamsKeeper.ParamsStore.Get(ctx) - if err != nil { - return nil, err - } - consensusParams.Abci.VoteExtensionsEnableHeight = ctx.BlockHeight() + 1 - err = keepers.ConsensusParamsKeeper.ParamsStore.Set(ctx, consensusParams) - if err != nil { - return nil, err - } - - return migrations, nil - } -} diff --git a/app/upgrades/mainnet/v1/core_contract_d482138dc00ff9767e09e96fea92fc5bf13f948d.wasm b/app/upgrades/mainnet/v1/core_contract_d482138dc00ff9767e09e96fea92fc5bf13f948d.wasm deleted file mode 100644 index 29eb41a5..00000000 Binary files a/app/upgrades/mainnet/v1/core_contract_d482138dc00ff9767e09e96fea92fc5bf13f948d.wasm and /dev/null differ diff --git a/app/upgrades/testnet/v1.0.0-rc.4/constants.go b/app/upgrades/testnet/v1.0.0-rc.4/constants.go deleted file mode 100644 index 8d09617c..00000000 --- a/app/upgrades/testnet/v1.0.0-rc.4/constants.go +++ /dev/null @@ -1,42 +0,0 @@ -package v1rc4 - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" -) - -const ( - UpgradeName = "v1.0.0-rc.4" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{}, - Deleted: []string{}, - }, -} - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - _ *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Add additional upgrade logic when needed - - /* - * migrations are run in module name alphabetical - * ascending order, except x/auth which is run last - */ - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/app/upgrades/testnet/v1.0.0-rc.6/constants.go b/app/upgrades/testnet/v1.0.0-rc.6/constants.go deleted file mode 100644 index c4d58345..00000000 --- a/app/upgrades/testnet/v1.0.0-rc.6/constants.go +++ /dev/null @@ -1,42 +0,0 @@ -package v1rc6 - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" - "github.com/sedaprotocol/seda-chain/app/upgrades" -) - -const ( - UpgradeName = "v1.0.0-rc.6" -) - -var Upgrade = upgrades.Upgrade{ - UpgradeName: UpgradeName, - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: storetypes.StoreUpgrades{ - Added: []string{}, - Deleted: []string{}, - }, -} - -func CreateUpgradeHandler( - mm upgrades.ModuleManager, - configurator module.Configurator, - _ *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // Add additional upgrade logic when needed - - /* - * migrations are run in module name alphabetical - * ascending order, except x/auth which is run last - */ - return mm.RunMigrations(ctx, configurator, fromVM) - } -} diff --git a/app/upgrades/types.go b/app/upgrades/types.go deleted file mode 100644 index a4021e53..00000000 --- a/app/upgrades/types.go +++ /dev/null @@ -1,23 +0,0 @@ -package upgrades - -import ( - "context" - - storetypes "cosmossdk.io/store/types" - upgradetypes "cosmossdk.io/x/upgrade/types" - - "github.com/cosmos/cosmos-sdk/types/module" - - "github.com/sedaprotocol/seda-chain/app/keepers" -) - -type ModuleManager interface { - RunMigrations(ctx context.Context, cfg module.Configurator, fromVM module.VersionMap) (module.VersionMap, error) - GetVersionMap() module.VersionMap -} - -type Upgrade struct { - UpgradeName string - CreateUpgradeHandler func(ModuleManager, module.Configurator, *keepers.AppKeepers) upgradetypes.UpgradeHandler - StoreUpgrades storetypes.StoreUpgrades -} diff --git a/go.mod b/go.mod index b2d61b95..b0562f9d 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/sedaprotocol/seda-chain go 1.23.5 -toolchain go1.24.2 - require ( cosmossdk.io/api v0.7.6 cosmossdk.io/client/v2 v2.0.0-beta.3 @@ -56,6 +54,7 @@ require ( go.uber.org/mock v0.4.0 golang.org/x/crypto v0.32.0 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 + golang.org/x/mod v0.22.0 google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a google.golang.org/grpc v1.70.0 google.golang.org/protobuf v1.36.5 diff --git a/go.sum b/go.sum index b09eea1a..e21232e5 100644 --- a/go.sum +++ b/go.sum @@ -1181,6 +1181,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/interchaintest/go.mod b/interchaintest/go.mod index c24699b4..5bae0785 100644 --- a/interchaintest/go.mod +++ b/interchaintest/go.mod @@ -19,6 +19,7 @@ require ( github.com/strangelove-ventures/interchaintest/v8 v8.1.0 github.com/stretchr/testify v1.10.0 go.uber.org/zap v1.26.0 + golang.org/x/sync v0.10.0 ) require ( @@ -237,7 +238,6 @@ require ( golang.org/x/mod v0.19.0 // indirect golang.org/x/net v0.34.0 // indirect golang.org/x/oauth2 v0.24.0 // indirect - golang.org/x/sync v0.10.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/term v0.28.0 // indirect golang.org/x/text v0.21.0 // indirect diff --git a/plugins/indexing/tally/module.go b/plugins/indexing/core/module.go similarity index 70% rename from plugins/indexing/tally/module.go rename to plugins/indexing/core/module.go index 97d287cd..f07866d2 100644 --- a/plugins/indexing/tally/module.go +++ b/plugins/indexing/core/module.go @@ -1,4 +1,4 @@ -package tally +package core import ( "bytes" @@ -9,20 +9,20 @@ import ( "github.com/sedaprotocol/seda-chain/plugins/indexing/log" "github.com/sedaprotocol/seda-chain/plugins/indexing/types" - tallytypes "github.com/sedaprotocol/seda-chain/x/tally/types" + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" ) -const StoreKey = tallytypes.StoreKey +const StoreKey = coretypes.StoreKey -type Params tallytypes.Params +type Params coretypes.Params func (p Params) MarshalJSON() ([]byte, error) { return types.MarshalJSJSON(p) } func ExtractUpdate(ctx *types.BlockContext, cdc codec.Codec, logger *log.Logger, change *storetypes.StoreKVPair) (*types.Message, error) { - if _, found := bytes.CutPrefix(change.Key, tallytypes.ParamsPrefix); found { - val, err := codec.CollValue[tallytypes.Params](cdc).Decode(change.Value) + if _, found := bytes.CutPrefix(change.Key, coretypes.ParamsKey); found { + val, err := codec.CollValue[coretypes.Params](cdc).Decode(change.Value) if err != nil { return nil, err } @@ -31,7 +31,7 @@ func ExtractUpdate(ctx *types.BlockContext, cdc codec.Codec, logger *log.Logger, ModuleName string `json:"moduleName"` Params Params `json:"params"` }{ - ModuleName: "tally", + ModuleName: "core", Params: Params(val), } diff --git a/plugins/indexing/plugin.go b/plugins/indexing/plugin.go index cb883880..03f31c04 100644 --- a/plugins/indexing/plugin.go +++ b/plugins/indexing/plugin.go @@ -50,17 +50,17 @@ import ( "github.com/sedaprotocol/seda-chain/plugins/indexing/bank" "github.com/sedaprotocol/seda-chain/plugins/indexing/base" "github.com/sedaprotocol/seda-chain/plugins/indexing/batching" + "github.com/sedaprotocol/seda-chain/plugins/indexing/core" dataproxy "github.com/sedaprotocol/seda-chain/plugins/indexing/data-proxy" "github.com/sedaprotocol/seda-chain/plugins/indexing/log" oracleprogram "github.com/sedaprotocol/seda-chain/plugins/indexing/oracle-program" "github.com/sedaprotocol/seda-chain/plugins/indexing/pluginaws" "github.com/sedaprotocol/seda-chain/plugins/indexing/pubkey" - "github.com/sedaprotocol/seda-chain/plugins/indexing/tally" "github.com/sedaprotocol/seda-chain/plugins/indexing/types" batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" - tallytypes "github.com/sedaprotocol/seda-chain/x/tally/types" vestingtypes "github.com/sedaprotocol/seda-chain/x/vesting/types" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" ) @@ -137,8 +137,8 @@ func (p *IndexerPlugin) extractUpdate(change *storetypes.StoreKVPair) (*types.Me return batching.ExtractUpdate(p.block, p.cdc, p.logger, change) case oracleprogram.StoreKey: return oracleprogram.ExtractUpdate(p.block, p.cdc, p.logger, change) - case tally.StoreKey: - return tally.ExtractUpdate(p.block, p.cdc, p.logger, change) + case core.StoreKey: + return core.ExtractUpdate(p.block, p.cdc, p.logger, change) default: return nil, nil } @@ -235,7 +235,7 @@ func main() { crisistypes.RegisterInterfaces(interfaceRegistry) packetforwardtypes.RegisterInterfaces(interfaceRegistry) wasmstoragetypes.RegisterInterfaces(interfaceRegistry) - tallytypes.RegisterInterfaces(interfaceRegistry) + coretypes.RegisterInterfaces(interfaceRegistry) dataproxytypes.RegisterInterfaces(interfaceRegistry) batchingtypes.RegisterInterfaces(interfaceRegistry) diff --git a/proto/sedachain/core/v1/core.proto b/proto/sedachain/core/v1/core.proto new file mode 100644 index 00000000..459d0e0e --- /dev/null +++ b/proto/sedachain/core/v1/core.proto @@ -0,0 +1,203 @@ +syntax = "proto3"; +package sedachain.core.v1; + +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/sedaprotocol/seda-chain/x/core/types"; + +// Staker is an identity that has staked SEDA tokens to perform data request +// execution. +message Staker { + string public_key = 1; + string memo = 2; + string staked = 3 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + string pending_withdrawal = 4 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false + ]; + uint64 sequence_num = 5; +} + +// DataRequest is a data request object. +message DataRequest { + // Hex-encoded ID of the data request + string i_d = 1 [ (gogoproto.jsontag) = "id" ]; + // Semantic versioning + string version = 2; + // Hex-encoded ID (hash) of the execution program + string exec_program_i_d = 3 [ (gogoproto.jsontag) = "exec_program_id" ]; + // Inputs for the execution program + bytes exec_inputs = 4; + // Gas limit for execution program execution + uint64 exec_gas_limit = 5; + // Hex-encoded ID (hash) of the tally program + string tally_program_i_d = 6 [ (gogoproto.jsontag) = "tally_program_id" ]; + // Inputs for the tally program + bytes tally_inputs = 7; + // Gas limit for tally program execution + uint64 tally_gas_limit = 8; + // Number of required data request executors (used as uint16) + uint32 replication_factor = 9; + // Specifications for the filter process + bytes consensus_filter = 10; + // Amount of SEDA tokens per unit gas (used as uint128) + string gas_price = 11 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // Public information attached to the data request + bytes memo = 12; + // Set by the relayer + bytes payback_address = 13; + // Set by SEDA Protocol (e.g. OEV-enabled data requests) + bytes s_e_d_a_payload = 14; + // Height at which the data request was posted + int64 posted_height = 15; + // Actual gas price derived by dividing attached funds by the total gas limit + // (may be higher than the minimum gas price) + string posted_gas_price = 16 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // Map from staker public keys to commits. + map commits = 17; + // Map from staker public keys to placeholder booleans. + map reveals = 18; + // Poster of the data request (Bech32 string) + string poster = 19; + // Funds escrowed for the data request + string escrow = 20 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // Timeout height of the data request (-1 if not set, i.e., under tallying + // status) + int64 timeout_height = 21; + // Status of the data request + DataRequestStatus status = 22; +} + +// DataRequestStatus is the status of a data request. +enum DataRequestStatus { + option (gogoproto.goproto_enum_prefix) = false; + + // Zero value as required by proto3. + DATA_REQUEST_STATUS_UNSPECIFIED = 0; + // Data request has been posted and is collecting commits. + DATA_REQUEST_STATUS_COMMITTING = 1; + // The number of commits has reached the replication factor, and the data + // request is now collecting reveals. + DATA_REQUEST_STATUS_REVEALING = 2; + // The number of reveals has reached the replication factor, and the data + // request is now ready to be tallied. + DATA_REQUEST_STATUS_TALLYING = 3; +} + +// RevealBody is the content of a reveal. +message RevealBody { + // Hex-encoded ID of the data request + string dr_id = 1; + // Block height of the data request posting + uint64 dr_block_height = 2; + // Exit code of the data request execution (used as uint8) + uint32 exit_code = 3; + // Gas used by the data request execution + uint64 gas_used = 4; + // Contents of the reveal + bytes reveal = 5; + // List of data proxy public keys used + repeated string proxy_pub_keys = 6 + [ (gogoproto.jsontag) = "proxy_public_keys" ]; +} + +// Params defines the parameters for the core module. +message Params { + DataRequestConfig data_request_config = 1 [ (gogoproto.nullable) = false ]; + StakingConfig staking_config = 2 [ (gogoproto.nullable) = false ]; + TallyConfig tally_config = 3 [ (gogoproto.nullable) = false ]; +} + +// DataRequestConfig defines data request-related parameters. +message DataRequestConfig { + // Number of blocks after which a data request is timed out while waiting + // for commits. + uint32 commit_timeout_in_blocks = 1; + // Number of blocks after which a data request is timed out while waiting + // for reveals. + uint32 reveal_timeout_in_blocks = 2; + // Delay in blocks before the backup executors are allowed to start executing + // the data request. + uint32 backup_delay_in_blocks = 3; + // Maximum size of all the reveals in a data request. + uint32 dr_reveal_size_limit_in_bytes = 4; + // Maximum size of the input for the execution program. + uint32 exec_input_limit_in_bytes = 5; + // Maximum size of the input for the tally program. + uint32 tally_input_limit_in_bytes = 6; + // Maximum size of the consensus filter. + uint32 consensus_filter_limit_in_bytes = 7; + // Maximum size of the memo. + uint32 memo_limit_in_bytes = 8; + // Maximum size of the payback address. + uint32 payback_address_limit_in_bytes = 9; + // Maximum size of the SEDA payload. + uint32 s_e_d_a_payload_limit_in_bytes = 10; +} + +// StakingConfig defines staking-related parameters. +message StakingConfig { + // MiminumStake is the minimum amount of SEDA tokens required to register as + // an Overlay. + string minimum_stake = 1 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // AllowlistEnabled is a flag that indicates whether the allowlist is enabled. + bool allowlist_enabled = 2; +} + +// TallyConfig definfes tally-related parameters. +message TallyConfig { + // MaxTallyGasLimit is the maximum gas limit for a tally request. + uint64 max_tally_gas_limit = 1; + // FilterGasCostNone is the gas cost for a filter type none. + uint64 filter_gas_cost_none = 2; + // FilterGasCostMultiplierMode is the gas cost multiplier for a filter type + // mode. + uint64 filter_gas_cost_multiplier_mode = 3; + // FilterGasCostMAD is the gas cost multiplier for a filter type + // Median Absolute Deviation. + uint64 filter_gas_cost_multiplier_m_a_d = 4; + // GasCostBase is the base gas cost for a data request. + uint64 gas_cost_base = 5; + // GasCostFallback is the gas cost incurred for data request execution when + // even basic consensus has not been reached. + uint64 execution_gas_cost_fallback = 6; + // BurnRatio is the ratio of the gas cost to be burned in case of reduced + // payout scenarios. + string burn_ratio = 7 [ + (cosmos_proto.scalar) = "cosmos.Dec", + (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", + (amino.dont_omitempty) = true, + (gogoproto.nullable) = false + ]; + // MaxResultSize is the maximum size of the result of a data request in bytes. + uint32 max_result_size = 8; + // MaxTalliesPerBlock specifies the maximum number of tallies per block. + uint32 max_tallies_per_block = 9; +} diff --git a/proto/sedachain/core/v1/genesis.proto b/proto/sedachain/core/v1/genesis.proto new file mode 100644 index 00000000..cf0a8bc1 --- /dev/null +++ b/proto/sedachain/core/v1/genesis.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package sedachain.core.v1; + +import "gogoproto/gogo.proto"; +import "sedachain/core/v1/core.proto"; + +option go_package = "github.com/sedaprotocol/seda-chain/x/core/types"; + +// GenesisState defines core module's genesis state. +message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/sedachain/tally/v1/query.proto b/proto/sedachain/core/v1/query.proto similarity index 61% rename from proto/sedachain/tally/v1/query.proto rename to proto/sedachain/core/v1/query.proto index 9ba0c076..be0987f6 100644 --- a/proto/sedachain/tally/v1/query.proto +++ b/proto/sedachain/core/v1/query.proto @@ -1,17 +1,17 @@ syntax = "proto3"; -package sedachain.tally.v1; +package sedachain.core.v1; import "google/api/annotations.proto"; import "gogoproto/gogo.proto"; -import "sedachain/tally/v1/tally.proto"; +import "sedachain/core/v1/core.proto"; -option go_package = "github.com/sedaprotocol/seda-chain/x/tally/types"; +option go_package = "github.com/sedaprotocol/seda-chain/x/core/types"; // Query defines the gRPC querier service. service Query { - // Params returns the total set of tally parameters. + // Params returns the total set of core parameters. rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { - option (google.api.http).get = "/seda-chain/tally/params"; + option (google.api.http).get = "/seda-chain/core/params"; } } @@ -20,6 +20,6 @@ message QueryParamsRequest {} // QueryParamsResponse is the response type for the Query/Params RPC method. message QueryParamsResponse { - // params defines the parameters of the module. + // Params defines the parameters of the module. Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/sedachain/core/v1/tx.proto b/proto/sedachain/core/v1/tx.proto new file mode 100644 index 00000000..5ccd63ff --- /dev/null +++ b/proto/sedachain/core/v1/tx.proto @@ -0,0 +1,151 @@ +syntax = "proto3"; +package sedachain.core.v1; + +import "gogoproto/gogo.proto"; +import "amino/amino.proto"; +import "cosmos_proto/cosmos.proto"; +import "cosmos/msg/v1/msg.proto"; +import "cosmos/base/v1beta1/coin.proto"; +import "sedachain/core/v1/core.proto"; + +option go_package = "github.com/sedaprotocol/seda-chain/x/core/types"; + +// Msg defines the core Msg service. +service Msg { + option (cosmos.msg.v1.service) = true; + + // AddToAllowlist adds a new address to the allowlist. + rpc AddToAllowlist(MsgAddToAllowlist) returns (MsgAddToAllowlistResponse); + + // Stake adds a stake to the executor identity. + rpc Stake(MsgStake) returns (MsgStakeResponse); + + // PostDataRequest posts a data request. + rpc PostDataRequest(MsgPostDataRequest) returns (MsgPostDataRequestResponse); + + // Commit makes a commitment to reveal a data result. + rpc Commit(MsgCommit) returns (MsgCommitResponse); + + // Reveal reveals a data result. + rpc Reveal(MsgReveal) returns (MsgRevealResponse); + + // UpdateParams updates the module's parameters. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// The request message for the AddToAllowlist method. +message MsgAddToAllowlist { + option (cosmos.msg.v1.signer) = "sender"; + + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string public_key = 2; +} + +// The response message for the AddToAllowlist method. +message MsgAddToAllowlistResponse {} + +// The request message for the Stake method. +message MsgStake { + option (cosmos.msg.v1.signer) = "sender"; + + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string public_key = 2; + string memo = 3; + // Proof is hex-encoded proof of the identity. + string proof = 4; + cosmos.base.v1beta1.Coin stake = 5 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; +} + +// The response message for the Stake method. +message MsgStakeResponse {} + +// The request message for the PostDataRequest method. +message MsgPostDataRequest { + option (cosmos.msg.v1.signer) = "sender"; + + // Poster of the data request + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + // Funds attached to the data request posting + cosmos.base.v1beta1.Coin funds = 2 + [ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ]; + // Semantic versioning + string version = 3; + // Hex-encoded ID (hash) of the execution program + string exec_program_id = 4; + // Inputs for the execution program + bytes exec_inputs = 5; + // Gas limit for execution program execution + uint64 exec_gas_limit = 6; + // Hex-encoded ID (hash) of the tally program + string tally_program_id = 7; + // Inputs for the tally program + bytes tally_inputs = 8; + // Gas limit for tally program execution + uint64 tally_gas_limit = 9; + // Number of required data request executors (used as uint16) + uint32 replication_factor = 10; + // Specifications for the filter process + bytes consensus_filter = 11; + // Amount of SEDA tokens per unit gas (used as uint128) + string gas_price = 12 [ + (cosmos_proto.scalar) = "cosmos.Int", + (gogoproto.customtype) = "cosmossdk.io/math.Int", + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true + ]; + // Public information attached to the data request + bytes memo = 13; + // Set by SEDA Protocol (e.g. OEV-enabled data requests) + bytes s_e_d_a_payload = 14; + // Set by the relayer + bytes payback_address = 15; +} + +// The response message for the PostDataRequest method. +message MsgPostDataRequestResponse { + // DrId is the hex-encoded ID of the data request. + string dr_id = 1; + // Height is the block height at which the data request was posted. + int64 height = 2; +} + +// The request message for the Commit method. +message MsgCommit { + option (cosmos.msg.v1.signer) = "sender"; + + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + string dr_id = 2; + string commit = 3; + string public_key = 4; + string proof = 5; +} + +// The response message for the Commit method. +message MsgCommitResponse {} + +// The request message for the Reveal method. +message MsgReveal { + option (cosmos.msg.v1.signer) = "sender"; + + string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + RevealBody reveal_body = 2; + string public_key = 3; + string proof = 4; + repeated string stderr = 5; + repeated string stdout = 6; +} + +// The response message for the Reveal method. +message MsgRevealResponse {} + +// The request message for the UpdateParams method. +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "authority"; + + string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; + Params params = 2 [ (gogoproto.nullable) = false ]; +} + +// The response message for the UpdateParams method. +message MsgUpdateParamsResponse {} diff --git a/proto/sedachain/tally/v1/genesis.proto b/proto/sedachain/tally/v1/genesis.proto deleted file mode 100644 index 869947d1..00000000 --- a/proto/sedachain/tally/v1/genesis.proto +++ /dev/null @@ -1,10 +0,0 @@ -syntax = "proto3"; -package sedachain.tally.v1; - -import "gogoproto/gogo.proto"; -import "sedachain/tally/v1/tally.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/tally/types"; - -// GenesisState defines tally module's genesis state. -message GenesisState { Params params = 1 [ (gogoproto.nullable) = false ]; } diff --git a/proto/sedachain/tally/v1/tally.proto b/proto/sedachain/tally/v1/tally.proto deleted file mode 100644 index 6351be0b..00000000 --- a/proto/sedachain/tally/v1/tally.proto +++ /dev/null @@ -1,39 +0,0 @@ -syntax = "proto3"; -package sedachain.tally.v1; - -import "cosmos_proto/cosmos.proto"; -import "gogoproto/gogo.proto"; -import "amino/amino.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/tally/types"; - -// Params defines the parameters for the tally module. -message Params { - // MaxTallyGasLimit is the maximum gas limit for a tally request. - uint64 max_tally_gas_limit = 1; - // FilterGasCostNone is the gas cost for a filter type none. - uint64 filter_gas_cost_none = 2; - // FilterGasCostMultiplierMode is the gas cost multiplier for a filter type - // mode. - uint64 filter_gas_cost_multiplier_mode = 3; - // FilterGasCostMAD is the gas cost multiplier for a filter type - // Median Absolute Deviation. - uint64 filter_gas_cost_multiplier_m_a_d = 4; - // GasCostBase is the base gas cost for a data request. - uint64 gas_cost_base = 5; - // GasCostFallback is the gas cost incurred for data request execution when - // even basic consensus has not been reached. - uint64 execution_gas_cost_fallback = 6; - // BurnRatio is the ratio of the gas cost to be burned in case of reduced - // payout scenarios. - string burn_ratio = 7 [ - (cosmos_proto.scalar) = "cosmos.Dec", - (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", - (amino.dont_omitempty) = true, - (gogoproto.nullable) = false - ]; - // MaxResultSize is the maximum size of the result of a data request in bytes. - uint32 max_result_size = 8; - // MaxTalliesPerBlock specifies the maximum number of tallies per block. - uint32 max_tallies_per_block = 9; -} diff --git a/proto/sedachain/tally/v1/tx.proto b/proto/sedachain/tally/v1/tx.proto deleted file mode 100644 index ae05e263..00000000 --- a/proto/sedachain/tally/v1/tx.proto +++ /dev/null @@ -1,30 +0,0 @@ -syntax = "proto3"; -package sedachain.tally.v1; - -import "gogoproto/gogo.proto"; -import "cosmos_proto/cosmos.proto"; -import "cosmos/msg/v1/msg.proto"; -import "sedachain/tally/v1/tally.proto"; - -option go_package = "github.com/sedaprotocol/seda-chain/x/tally/types"; - -// Msg defines the tally Msg service. -service Msg { - option (cosmos.msg.v1.service) = true; - - // The UpdateParams method updates the module's parameters. - rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); -} - -// The request message for the UpdateParams method. -message MsgUpdateParams { - option (cosmos.msg.v1.signer) = "authority"; - - // authority is the address that controls the module (defaults to x/gov unless - // overwritten). - string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ]; - Params params = 2 [ (gogoproto.nullable) = false ]; -} - -// The response message for the UpdateParams method. -message MsgUpdateParamsResponse {} diff --git a/testutil/contract_msgs.go b/testutil/contract_msgs.go index 381cf922..eed9c842 100644 --- a/testutil/contract_msgs.go +++ b/testutil/contract_msgs.go @@ -6,16 +6,15 @@ import ( "strings" ) -func CommitMsg(drID, commitment, stakerPubKey, proof string, gasUsed uint64) []byte { +func CommitMsg(drID, commitment, stakerPubKey, proof string) []byte { return []byte(fmt.Sprintf(`{ "commit_data_result": { "dr_id": "%s", "commitment": "%s", "public_key": "%s", - "proof": "%s", - "gas_used": %d + "proof": "%s" } - }`, drID, commitment, stakerPubKey, proof, gasUsed)) + }`, drID, commitment, stakerPubKey, proof)) } func RevealMsg(drID, reveal, stakerPubKey, proof string, proxyPubKeys []string, exitCode byte, drHeight, gasUsed uint64) []byte { diff --git a/testutil/integration.go b/testutil/integration.go index f1334f57..44362281 100644 --- a/testutil/integration.go +++ b/testutil/integration.go @@ -184,6 +184,11 @@ func (app *IntegationApp) Context() sdk.Context { return app.ctx } +// SetContextChainID sets the chainID of the application context. +func (app *IntegationApp) SetContextChainID(chainID string) { + app.ctx = app.ctx.WithChainID(chainID) +} + // SetContextTxBytes sets the txBytes of the application context. func (app *IntegationApp) SetContextTxBytes(txBytes []byte) { app.ctx = app.ctx.WithTxBytes(txBytes) diff --git a/x/batching/keeper/integration_test.go b/x/batching/keeper/integration_test.go index ae39b546..04ff52c6 100644 --- a/x/batching/keeper/integration_test.go +++ b/x/batching/keeper/integration_test.go @@ -49,16 +49,11 @@ import ( "github.com/sedaprotocol/seda-chain/x/batching" batchingkeeper "github.com/sedaprotocol/seda-chain/x/batching/keeper" "github.com/sedaprotocol/seda-chain/x/batching/types" - dataproxykeeper "github.com/sedaprotocol/seda-chain/x/data-proxy/keeper" - dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" "github.com/sedaprotocol/seda-chain/x/pubkey" pubkeykeeper "github.com/sedaprotocol/seda-chain/x/pubkey/keeper" pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" "github.com/sedaprotocol/seda-chain/x/staking" stakingkeeper "github.com/sedaprotocol/seda-chain/x/staking/keeper" - "github.com/sedaprotocol/seda-chain/x/tally" - tallykeeper "github.com/sedaprotocol/seda-chain/x/tally/keeper" - tallytypes "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" wasmstoragetestutil "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper/testutil" @@ -80,7 +75,6 @@ type fixture struct { contractKeeper wasmkeeper.PermissionedKeeper wasmKeeper wasmkeeper.Keeper wasmStorageKeeper wasmstoragekeeper.Keeper - tallyKeeper tallykeeper.Keeper pubKeyKeeper pubkeykeeper.Keeper batchingKeeper batchingkeeper.Keeper mockViewKeeper *wasmstoragetestutil.MockViewKeeper @@ -94,7 +88,7 @@ func initFixture(tb testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, sdkstakingtypes.StoreKey, wasmstoragetypes.StoreKey, - wasmtypes.StoreKey, pubkeytypes.StoreKey, tallytypes.StoreKey, types.StoreKey, slashingtypes.StoreKey, + wasmtypes.StoreKey, pubkeytypes.StoreKey, types.StoreKey, slashingtypes.StoreKey, ) cdc := moduletestutil.MakeTestEncodingConfig(auth.AppModuleBasic{}, bank.AppModuleBasic{}, wasmstorage.AppModuleBasic{}).Codec @@ -212,13 +206,6 @@ func initFixture(tb testing.TB) *fixture { ) stakingKeeper.SetPubKeyKeeper(pubKeyKeeper) - dataProxyKeeper := dataproxykeeper.NewKeeper( - cdc, - runtime.NewKVStoreService(keys[dataproxytypes.StoreKey]), - bankKeeper, - authtypes.NewModuleAddress("gov").String(), - ) - batchingKeeper := batchingkeeper.NewKeeper( cdc, runtime.NewKVStoreService(keys[types.StoreKey]), @@ -231,22 +218,10 @@ func initFixture(tb testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), ) - tallyKeeper := tallykeeper.NewKeeper( - cdc, - runtime.NewKVStoreService(keys[tallytypes.StoreKey]), - wasmStorageKeeper, - batchingKeeper, - dataProxyKeeper, - contractKeeper, - viewKeeper, - authority.String(), - ) - authModule := auth.NewAppModule(cdc, accountKeeper, app.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper, pubKeyKeeper) wasmStorageModule := wasmstorage.NewAppModule(cdc, *wasmStorageKeeper) - tallyModule := tally.NewAppModule(cdc, tallyKeeper) pubKeyModule := pubkey.NewAppModule(cdc, pubKeyKeeper) batchingModule := batching.NewAppModule(cdc, batchingKeeper) @@ -255,7 +230,6 @@ func initFixture(tb testing.TB) *fixture { banktypes.ModuleName: bankModule, sdkstakingtypes.ModuleName: stakingModule, wasmstoragetypes.ModuleName: wasmStorageModule, - tallytypes.ModuleName: tallyModule, pubkeytypes.ModuleName: pubKeyModule, types.ModuleName: batchingModule, }) @@ -270,7 +244,6 @@ func initFixture(tb testing.TB) *fixture { contractKeeper: *contractKeeper, wasmKeeper: wasmKeeper, wasmStorageKeeper: *wasmStorageKeeper, - tallyKeeper: tallyKeeper, pubKeyKeeper: *pubKeyKeeper, batchingKeeper: batchingKeeper, mockViewKeeper: viewKeeper, diff --git a/x/tally/README.md b/x/core/README.md similarity index 75% rename from x/tally/README.md rename to x/core/README.md index e0ace096..7d27fc44 100644 --- a/x/tally/README.md +++ b/x/core/README.md @@ -1,7 +1,11 @@ -# Tally Module +# Core Module ## Overview -Primarily, the tally module aggregates the Oracle Program execution results reported by the Overlay Nodes, detects outliers, and calculates payouts. +The core module provides interface for the SEDA users to make data requests and Overlay operators to stake, commit, and reveal. + +It also tallies the Oracle Program execution results reported by the Overlay Nodes, detects outliers, and calculates payouts. + + ## Tally Flow ```mermaid @@ -33,7 +37,7 @@ flowchart TD G3 ----> Z(("Done")) ``` -At every block, the end blocker of the tally module queries the Core Contract for the list of data requests that are ready to be tallied. The tally process for a given data request involves the following sequence: +At every block, the end blocker of the core module queries the Core Contract for the list of data requests that are ready to be tallied. The tally process for a given data request involves the following sequence: 1. *Filtering*: The goal of filtering is to determine whether there is sufficient consensus among the reveals by the Overlay Nodes. The outcome of filter determines the future flow of tally operation on the data request. First, if there is less than 2/3 agreement on the success-or-fail of the execution and the data proxy public keys used during the execution, the outcome of tally is `ErrorNoBasicConsensus`. Otherwise, the module builds a filter based on the input provided by the data requestor. If there is an error while building a filter, the outcome of tally is `ErrorInvalidFilterInput`. Finally, if there is no error up to this point, the module applies the filter, whose outcome is `NoError` (= consensus), `ErrorConsensusInError` (more than 2/3 of reveals are failed executions or cannot be parsed), or `ErrorNoConsensus` (1/3 or more of reveals are deemed “outliers”). Note the definition of “outlier” depends on the type of filter: - None filter: No reveal is an outlier, even if it cannot be parsed. - Mode filter: A reveal is an outlier if its parsed value is not equal to the most frequent parsed reveal value. @@ -47,7 +51,7 @@ At every block, the end blocker of the tally module queries the Core Contract fo Note the data proxy’s fee is retrieved from the data-proxy module and the gas price from the data request. - The remaining part of the execution gas is due to the executors’ work. However, since the gas reports from the Overlay Nodes cannot be blindly trusted, the tally module calculates the “canonical” gas consumptions by the executors. Given `n` gas reports, they are first adjusted by the previously computed data proxy gas consumption and the remaining execution gas. The adjusted gas report `R_i` for executor `i` is + The remaining part of the execution gas is due to the executors’ work. However, since the gas reports from the Overlay Nodes cannot be blindly trusted, the core module calculates the “canonical” gas consumptions by the executors. Given `n` gas reports, they are first adjusted by the previously computed data proxy gas consumption and the remaining execution gas. The adjusted gas report `R_i` for executor `i` is $$ R_i=\min \left( \left\lfloor\frac{\text{RemainingExecGas}}{\text{ReplicationFactor}}\right\rfloor, \text{reportedGas}_i-\Sigma_j \text{proxyGasUsed}_j \right) @@ -90,7 +94,7 @@ At every block, the end blocker of the tally module queries the Core Contract fo \text{TotalShares} = \left(\text{Median} \times (\text{RF} - 1)\right) + (\text{Low} \times 2) $$ - The calculated execution gas consumption is returned in the tally result along with the tally gas consumption, which is the gas used by the tally module for filtering and tally VM execution. These gas calculations are converted into payout distribution messages, which are then delivered to the Core Contract for actual executions of funds transfers. Note the tally gas is burned, whereas the data proxy gas and executor gas are paid to the data proxies and executors, respectively. The table below describes the payout depending on the filter/tally outcome. + The calculated execution gas consumption is returned in the tally result along with the tally gas consumption, which is the gas used by the core module for filtering and tally VM execution. These gas calculations are converted into payout distribution messages, which are then delivered to the Core Contract for actual executions of funds transfers. Note the tally gas is burned, whereas the data proxy gas and executor gas are paid to the data proxies and executors, respectively. The table below describes the payout depending on the filter/tally outcome. ⬇️ Order of error detection ➡️ Order of payment (The burns are combined in one burn execution) @@ -107,11 +111,17 @@ At every block, the end blocker of the tally module queries the Core Contract fo Once the filtering - tally VM execution - gas calculation sequence is completed, and the results are reported back to the Core Contract, data result entries are stored in the batching module under batch-ready status. -Note the tally module’s end blocker is structured so that most errors are caught and logged without causing the chain to halt. Only the most critical operations such as data result ID calculation or state writes can return an error. +Note the core module’s end blocker is structured so that most errors are caught and logged without causing the chain to halt. Only the most critical operations such as data result ID calculation or state writes can return an error. ## State ``` -0x00 -> parameters +allowlist: 0x00 -> []PublicKey +stakers: 0x01 | PublicKey -> Staker +dataRequests: 0x02 | DR_ID -> DataRequest +revealBodies: 0x03 | DR_ID | PublicKey -> RevealBody +committing: 0x04 | DataRequestIndex -> () +revealing: 0x05 | DataRequestIndex -> () +tallying: 0x06 | DataRequestIndex -> () +timeoutQueue: 0x07 | DR_ID | Timeout_Height -> () +params: 0x08 -> Params ``` - - diff --git a/x/tally/client/cli/query.go b/x/core/client/cli/query.go similarity index 91% rename from x/tally/client/cli/query.go rename to x/core/client/cli/query.go index e25fba60..33cc99d2 100644 --- a/x/tally/client/cli/query.go +++ b/x/core/client/cli/query.go @@ -8,7 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) // GetQueryCmd returns the CLI query commands for this module. @@ -29,7 +29,7 @@ func GetQueryCmd() *cobra.Command { func GetCmdQueryParams() *cobra.Command { cmd := &cobra.Command{ Use: "params", - Short: "Query tally module parameters", + Short: "Query core module parameters", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) diff --git a/x/core/keeper/benchmark_endblock_test.go b/x/core/keeper/benchmark_endblock_test.go new file mode 100644 index 00000000..ac25780e --- /dev/null +++ b/x/core/keeper/benchmark_endblock_test.go @@ -0,0 +1,80 @@ +package keeper_test + +// import ( +// "encoding/base64" +// "fmt" +// "testing" + +// "github.com/stretchr/testify/require" +// "golang.org/x/exp/rand" + +// "cosmossdk.io/math" + +// sdk "github.com/cosmos/cosmos-sdk/types" + +// "github.com/sedaprotocol/seda-chain/testutil/testwasms" +// "github.com/sedaprotocol/seda-chain/x/core/types" +// ) + +// func BenchmarkDataRequestFlow(b *testing.B) { +// f := initFixture(b) + +// proxyPubKeys := []string{"03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"} +// err := f.SetDataProxyConfig(proxyPubKeys[0], "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f", sdk.NewCoin(bondDenom, math.NewInt(1000000000000000000))) +// require.NoError(b, err) + +// params := types.DefaultParams() +// params.TallyConfig.MaxTalliesPerBlock = 1000 +// f.keeper.SetParams(f.Context(), params) + +// for i := 0; i < b.N; i++ { +// b.StopTimer() +// for j := 0; j < 1000; j++ { +// f.executeDataRequestFlow( +// b, nil, nil, +// 1, 1, 1, false, +// commitRevealConfig{ +// requestHeight: 1, +// requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), +// reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), +// proxyPubKeys: proxyPubKeys, +// gasUsed: 150000000000000000, +// }) +// } + +// b.StartTimer() +// err = f.keeper.EndBlock(f.Context()) +// require.NoError(b, err) + +// f.AddBlock() +// } +// } + +// func BenchmarkBigTallyPrograms(b *testing.B) { +// f := initFixture(b) + +// params := types.DefaultParams() +// params.TallyConfig.MaxTalliesPerBlock = 1000 +// f.keeper.SetParams(f.Context(), params) + +// for i := 0; i < b.N; i++ { +// b.StopTimer() +// for j := 0; j < 1000; j++ { +// f.commitRevealDataRequest( +// b, nil, testwasms.BigWasm(), +// 1, 1, 1, false, +// commitRevealConfig{ +// requestHeight: 1, +// requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), +// reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), +// gasUsed: 150000000000000000, +// }) +// } + +// b.StartTimer() +// err := f.keeper.EndBlock(f.Context()) +// require.NoError(b, err) + +// f.AddBlock() +// } +// } diff --git a/x/core/keeper/core_benchmark_test.go b/x/core/keeper/core_benchmark_test.go new file mode 100644 index 00000000..f6b7bf2f --- /dev/null +++ b/x/core/keeper/core_benchmark_test.go @@ -0,0 +1,53 @@ +package keeper_test + +import ( + "encoding/base64" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "golang.org/x/exp/rand" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func BenchmarkDataRequestFlow(b *testing.B) { + f := initFixture(b) + proxyPubKeys := []string{"03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"} + err := f.SetDataProxyConfig(proxyPubKeys[0], "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f", sdk.NewCoin(bondDenom, math.NewInt(1000000000000000000))) + require.NoError(b, err) + + stakers := f.addStakers(b, 5) + + tt := struct { + replicationFactor int + numCommits int + numReveals int + timeout bool + }{ + replicationFactor: 1, + numCommits: 1, + numReveals: 1, + timeout: false, + } + + // b.Loop() is not supported in go 1.23 + // for b.Loop() { + for range b.N { + f.commitRevealDataRequests( + b, stakers, tt.replicationFactor, tt.numCommits, tt.numReveals, tt.timeout, + commitRevealConfig{ + requestHeight: 1, + requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), + reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), + proxyPubKeys: proxyPubKeys, + gasUsed: 150000000000000000, + }) + err = f.keeper.EndBlock(f.Context()) + require.NoError(b, err) + err = f.batchingKeeper.EndBlock(f.Context()) + require.NoError(b, err) + f.AddBlock() + } +} diff --git a/x/core/keeper/core_test.go b/x/core/keeper/core_test.go new file mode 100644 index 00000000..17519c56 --- /dev/null +++ b/x/core/keeper/core_test.go @@ -0,0 +1,91 @@ +package keeper_test + +import ( + "encoding/base64" + "testing" + + "github.com/stretchr/testify/require" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// TestDataRequestFlow is an integration test that tests the full flow of +// a data request. +func TestDataRequestFlow(t *testing.T) { + f := initFixture(t) + stakers := f.addStakers(t, 5) + + tests := []struct { + name string + memo string + replicationFactor int + numCommits int + numReveals int + timeout bool + expExitCode uint32 + }{ + { + name: "full single commit-reveal", + memo: base64.StdEncoding.EncodeToString([]byte("memo0")), + replicationFactor: 1, + numCommits: 1, + numReveals: 1, + timeout: false, + expExitCode: 0, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + proxyPubKeys := []string{"03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"} + err := f.SetDataProxyConfig(proxyPubKeys[0], "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f", sdk.NewCoin(bondDenom, math.NewInt(1000000000000000000))) + require.NoError(t, err) + + drID, stakers := f.commitRevealDataRequest( + t, stakers, tt.replicationFactor, tt.numCommits, tt.numReveals, tt.timeout, + commitRevealConfig{ + requestHeight: 1, + requestMemo: tt.memo, + reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), + proxyPubKeys: proxyPubKeys, + gasUsed: 150000000000000000, + }, + ) + + beforeBalance := f.bankKeeper.GetBalance(f.Context(), stakers[0].address, bondDenom) + posterBeforeBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) + + // Core Endblock + err = f.keeper.EndBlock(f.Context()) + require.NoError(t, err) + require.NotContains(t, f.logBuf.String(), "ERR") + + // TODO query get_staker pending_withdrawal and check diff + // Verify the staker did not pay for the transactions + afterBalance := f.bankKeeper.GetBalance(f.Context(), stakers[0].address, bondDenom) + diff := afterBalance.Sub(beforeBalance) + require.Equal(t, "0aseda", diff.String()) + + // Verify the poster paid for execution + afterPostBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) + diff = afterPostBalance.Sub(posterBeforeBalance) + require.NotEqual(t, "0aseda", diff.String(), "Poster should have payed for execution") + + dataResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), drID) + require.NoError(t, err) + require.Equal(t, tt.expExitCode, dataResult.ExitCode) + + dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) + require.NoError(t, err) + require.Contains(t, dataResults, *dataResult) + + // Batching Endblock + err = f.batchingKeeper.EndBlock(f.Context()) + require.NoError(t, err) + + batches, err := f.batchingKeeper.GetAllBatches(f.Context()) + require.NoError(t, err) + require.Equal(t, 1, len(batches)) + }) + } +} diff --git a/x/core/keeper/data_request_indexing.go b/x/core/keeper/data_request_indexing.go new file mode 100644 index 00000000..d608451b --- /dev/null +++ b/x/core/keeper/data_request_indexing.go @@ -0,0 +1,79 @@ +package keeper + +import ( + "cosmossdk.io/collections" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func (k Keeper) GetTallyingDataRequestIDs(ctx sdk.Context) ([]string, error) { + rng := collections.NewPrefixedPairRange[types.DataRequestStatus, types.DataRequestIndex](types.DATA_REQUEST_STATUS_TALLYING) + + iter, err := k.dataRequestIndexing.Iterate(ctx, rng) + if err != nil { + return nil, err + } + defer iter.Close() + + var ids []string + for ; iter.Valid(); iter.Next() { + key, err := iter.Key() + if err != nil { + return nil, err + } + ids = append(ids, key.K2().DrID()) + } + return ids, nil +} + +func (k Keeper) UpdateDataRequestIndexing(ctx sdk.Context, index types.DataRequestIndex, currentStatus, newStatus types.DataRequestStatus) error { + // Check the logic of the status transition, which follows: + // Unspecified (addition) -> Committing -> Revealing -> Tallying -> Unspecified (removal) + // except that in case of timeout, Committing -> Tallying is also possible. + switch currentStatus { + case types.DATA_REQUEST_STATUS_UNSPECIFIED: + if newStatus != types.DATA_REQUEST_STATUS_COMMITTING { + return types.ErrInvalidStatusTransition.Wrapf("%s -> %s", currentStatus, newStatus) + } + + case types.DATA_REQUEST_STATUS_COMMITTING: + if newStatus != types.DATA_REQUEST_STATUS_REVEALING && + newStatus != types.DATA_REQUEST_STATUS_TALLYING { + return types.ErrInvalidStatusTransition.Wrapf("%s -> %s", currentStatus, newStatus) + } + + case types.DATA_REQUEST_STATUS_REVEALING: + if newStatus != types.DATA_REQUEST_STATUS_TALLYING { + return types.ErrInvalidStatusTransition.Wrapf("%s -> %s", currentStatus, newStatus) + } + + case types.DATA_REQUEST_STATUS_TALLYING: + if newStatus != types.DATA_REQUEST_STATUS_UNSPECIFIED { + return types.ErrInvalidStatusTransition.Wrapf("%s -> %s", currentStatus, newStatus) + } + } + + if currentStatus != types.DATA_REQUEST_STATUS_UNSPECIFIED { + exists, err := k.dataRequestIndexing.Has(ctx, collections.Join(currentStatus, index)) + if err != nil { + return err + } + if !exists { + return types.ErrDataRequestNotFoundInIndex.Wrapf("data request ID %s, status %s", index.DrID(), currentStatus) + } + err = k.dataRequestIndexing.Remove(ctx, collections.Join(currentStatus, index)) + if err != nil { + return err + } + } + + if newStatus != types.DATA_REQUEST_STATUS_UNSPECIFIED { + err := k.dataRequestIndexing.Set(ctx, collections.Join(newStatus, index)) + if err != nil { + return err + } + } + return nil +} diff --git a/x/tally/types/data_result.go b/x/core/keeper/data_result.go similarity index 80% rename from x/tally/types/data_result.go rename to x/core/keeper/data_result.go index 97cab35b..34b0b9e8 100644 --- a/x/tally/types/data_result.go +++ b/x/core/keeper/data_result.go @@ -1,4 +1,4 @@ -package types +package keeper import ( "fmt" @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) // MarkResultAsFallback marks a DataResult as a fallback result. @@ -16,7 +17,7 @@ func MarkResultAsFallback(dataResult *batchingtypes.DataResult, tallyResult *Tal gasUsed := math.NewInt(0) dataResult.GasUsed = &gasUsed - dataResult.ExitCode = TallyExitCodeInvalidRequest + dataResult.ExitCode = types.TallyExitCodeInvalidRequest dataResult.Consensus = false dataResult.Result = []byte(fmt.Sprintf("unable to process request. error: %s", encounteredError.Error())) @@ -25,7 +26,7 @@ func MarkResultAsFallback(dataResult *batchingtypes.DataResult, tallyResult *Tal return err } - tallyResult.FilterResult = FilterResult{Error: ErrFilterDidNotRun} + tallyResult.FilterResult = FilterResult{Error: types.ErrFilterDidNotRun} return nil } @@ -36,7 +37,7 @@ func MarkResultAsPaused(dataResult *batchingtypes.DataResult, tallyResult *Tally gasUsed := math.NewInt(0) dataResult.GasUsed = &gasUsed - dataResult.ExitCode = TallyExitCodeContractPaused + dataResult.ExitCode = types.TallyExitCodeContractPaused dataResult.Consensus = false dataResult.Result = []byte("contract is paused") @@ -45,6 +46,6 @@ func MarkResultAsPaused(dataResult *batchingtypes.DataResult, tallyResult *Tally return err } - tallyResult.FilterResult = FilterResult{Error: ErrFilterDidNotRun} + tallyResult.FilterResult = FilterResult{Error: types.ErrFilterDidNotRun} return nil } diff --git a/x/tally/keeper/endblock.go b/x/core/keeper/endblock.go similarity index 52% rename from x/tally/keeper/endblock.go rename to x/core/keeper/endblock.go index eb7b60c1..8c66e07a 100644 --- a/x/tally/keeper/endblock.go +++ b/x/core/keeper/endblock.go @@ -1,22 +1,18 @@ package keeper import ( - "encoding/json" "errors" "fmt" "strconv" "strings" - errorsmod "cosmossdk.io/errors" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sedaprotocol/seda-wasm-vm/tallyvm/v3" batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) const ( @@ -25,74 +21,52 @@ const ( ) func (k Keeper) EndBlock(ctx sdk.Context) error { - coreContract, err := k.wasmStorageKeeper.GetCoreContractAddr(ctx) - if err != nil { - telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to get core contract address", "err", err) - return nil - } - if coreContract == nil { - k.Logger(ctx).Info("skipping tally end block - core contract has not been registered") - return nil - } - - postRes, err := k.wasmKeeper.Sudo(ctx, coreContract, []byte(`{"expire_data_requests":{}}`)) + // TODO Memory considerations (Check old queryContract with params.MaxTalliesPerBlock) + err := k.ExpireDataRequests(ctx) if err != nil { telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to expire data requests", "err", err) return nil } - k.Logger(ctx).Debug("sudo expire_data_requests", "res", postRes) - return k.Tally(ctx, coreContract) + return k.Tally(ctx) } -// Tally fetches from the Core Contract a list of tally-ready requests, tallies -// them, reports results to the contract, and stores results for batching. -func (k Keeper) Tally(ctx sdk.Context, coreContract sdk.AccAddress) error { - params, err := k.GetParams(ctx) +// Tally fetches from a list of tally-ready requests, tallies them, reports +// results to the contract, and stores results for batching. +func (k Keeper) Tally(ctx sdk.Context) error { + drIDs, err := k.GetTallyingDataRequestIDs(ctx) if err != nil { telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to get tally params", "err", err) + k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to get tallying data request IDs", "err", err) return nil } - tallyvm.TallyMaxBytes = uint(params.MaxResultSize) - contractQueryResponse, err := k.queryContract(ctx, coreContract, params.MaxTalliesPerBlock) - if err != nil { - telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to get tally-ready data requests", "err", err) - return nil - } - - tallyList := contractQueryResponse.DataRequests - if len(tallyList) == 0 { + tallyLen := len(drIDs) + if tallyLen == 0 { k.Logger(ctx).Debug("no tally-ready data requests - skipping tally process") return nil } k.Logger(ctx).Info("non-empty tally list - starting tally process") - tallyResults, dataResults, processedReqs, err := k.ProcessTallies(ctx, tallyList, params, contractQueryResponse.IsPaused) + params, err := k.GetParams(ctx) if err != nil { telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to tally data requests", "err", err) + k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to get tally params", "err", err) return nil } + tallyConfig := params.TallyConfig + tallyvm.TallyMaxBytes = uint(tallyConfig.MaxResultSize) - // Notify the Core Contract of tally completion. - msg, err := types.MarshalSudoRemoveDataRequests(processedReqs) + tallyResults, dataResults, err := k.ProcessTallies(ctx, drIDs, params, false) if err != nil { telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to marshal sudo remove data requests", "err", err) - return nil - } - _, err = k.wasmKeeper.Sudo(ctx, coreContract, msg) - if err != nil { - telemetry.SetGauge(1, types.TelemetryKeyDRFlowHalt) - k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to notify core contract of tally completion", "err", err) + k.Logger(ctx).Error("[HALTS_DR_FLOW] failed to tally data requests", "err", err) return nil } + // TODO remove_requests.rs + // Store the data results for batching. for i := range dataResults { err := k.batchingKeeper.SetDataResultForBatching(ctx, dataResults[i]) @@ -119,7 +93,7 @@ func (k Keeper) Tally(ctx sdk.Context, coreContract sdk.AccAddress) error { ) } - telemetry.SetGauge(float32(len(tallyList)), types.TelemetryKeyDataRequestsTallied) + telemetry.SetGauge(float32(tallyLen), types.TelemetryKeyDataRequestsTallied) telemetry.SetGauge(0, types.TelemetryKeyDRFlowHalt) return nil @@ -129,65 +103,60 @@ func (k Keeper) Tally(ctx sdk.Context, coreContract sdk.AccAddress) error { // of requests: Filtering -> VM execution -> Gas metering and distributions. // It returns the tally results, data results, processed list of requests // expected by the Core Contract, and an error. -func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, params types.Params, isPaused bool) ([]types.TallyResult, []batchingtypes.DataResult, map[string][]types.Distribution, error) { +func (k Keeper) ProcessTallies(ctx sdk.Context, drIDs []string, params types.Params, isPaused bool) ([]TallyResult, []batchingtypes.DataResult, error) { // tallyResults and dataResults have the same indexing. - tallyResults := make([]types.TallyResult, len(tallyList)) - dataResults := make([]batchingtypes.DataResult, len(tallyList)) + tallyResults := make([]TallyResult, len(drIDs)) + dataResults := make([]batchingtypes.DataResult, len(drIDs)) - processedReqs := make(map[string][]types.Distribution) tallyExecItems := []TallyParallelExecItem{} var err error - for i, req := range tallyList { - // Initialize the processedReqs map for each request with a full refund (no other distributions) - processedReqs[req.ID] = make([]types.Distribution, 0) - - tallyResults[i] = types.TallyResult{ - ID: req.ID, - Height: req.Height, - ReplicationFactor: req.ReplicationFactor, - } - - dataResults[i], err = req.ToResult(ctx) + for i, id := range drIDs { + dr, err := k.GetDataRequest(ctx, id) if err != nil { - markResultErr := types.MarkResultAsFallback(&dataResults[i], &tallyResults[i], err) - if markResultErr != nil { - return nil, nil, nil, err - } - continue + return nil, nil, err } - if isPaused { - markResultErr := types.MarkResultAsPaused(&dataResults[i], &tallyResults[i]) - if markResultErr != nil { - return nil, nil, nil, err - } - continue + dataResults[i] = batchingtypes.DataResult{ + DrId: dr.ID, + //nolint:gosec // G115: Block height is never negative. + DrBlockHeight: uint64(dr.PostedHeight), + Version: dr.Version, + //nolint:gosec // G115: Block height is never negative. + BlockHeight: uint64(ctx.BlockHeight()), + //nolint:gosec // G115: Timestamp is never negative. + BlockTimestamp: uint64(ctx.BlockTime().Unix()), } - postedGasPrice, ok := math.NewIntFromString(req.PostedGasPrice) - if !ok || !postedGasPrice.IsPositive() { - markResultErr := types.MarkResultAsFallback(&dataResults[i], &tallyResults[i], fmt.Errorf("invalid gas price: %s", req.PostedGasPrice)) - if markResultErr != nil { - return nil, nil, nil, err - } - continue + // TODO Add pausability + // if isPaused { + // markResultErr := MarkResultAsPaused(&dataResults[i], &tallyResults[i]) + // if markResultErr != nil { + // return nil, nil, nil, err + // } + // continue + // } + + tallyResults[i] = TallyResult{ + ID: dr.ID, + Height: uint64(dr.PostedHeight), + ReplicationFactor: uint16(dr.ReplicationFactor), } - gasMeter := types.NewGasMeter(req.TallyGasLimit, req.ExecGasLimit, params.MaxTallyGasLimit, postedGasPrice, params.GasCostBase) + gasMeter := types.NewGasMeter(&dr, params.TallyConfig.MaxTallyGasLimit, params.TallyConfig.GasCostBase) // Phase 1: Filtering - if len(req.Commits) < int(req.ReplicationFactor) { - tallyResults[i].FilterResult = types.FilterResult{Error: types.ErrFilterDidNotRun} - dataResults[i].Result = []byte(fmt.Sprintf("need %d commits; received %d", req.ReplicationFactor, len(req.Commits))) + if len(dr.Commits) < int(dr.ReplicationFactor) { + tallyResults[i].FilterResult = FilterResult{Error: types.ErrFilterDidNotRun} + dataResults[i].Result = []byte(fmt.Sprintf("need %d commits; received %d", dr.ReplicationFactor, len(dr.Commits))) dataResults[i].ExitCode = types.TallyExitCodeNotEnoughCommits - k.Logger(ctx).Info("data request's number of commits did not meet replication factor", "request_id", req.ID) + k.Logger(ctx).Info("data request's number of commits did not meet replication factor", "request_id", dr.ID) - MeterExecutorGasFallback(req, params.ExecutionGasCostFallback, gasMeter) + MeterExecutorGasFallback(dr, params.TallyConfig.ExecutionGasCostFallback, gasMeter) } else { - reveals, executors, gasReports := req.SanitizeReveals(ctx.BlockHeight()) - filterResult, filterErr := types.ExecuteFilter(reveals, req.ConsensusFilter, req.ReplicationFactor, params, gasMeter) + reveals, executors, gasReports := k.LoadRevealsSorted(ctx, dr.ID, dr.Reveals) + filterResult, filterErr := ExecuteFilter(reveals, dr.ConsensusFilter, uint16(dr.ReplicationFactor), params.TallyConfig, gasMeter) filterResult.Error = filterErr filterResult.Executors = executors @@ -199,7 +168,7 @@ func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, param if filterErr == nil { // Execute tally VM for this request. - tallyExecItems = append(tallyExecItems, NewTallyParallelExecItem(i, req, gasMeter, reveals, filterResult.Outliers, filterResult.Consensus)) + tallyExecItems = append(tallyExecItems, NewTallyParallelExecItem(i, dr, gasMeter, reveals, filterResult.Outliers, filterResult.Consensus)) } else { // Skip tally execution. dataResults[i].Result = []byte(filterErr.Error()) @@ -210,7 +179,7 @@ func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, param } if errors.Is(filterErr, types.ErrNoBasicConsensus) { - MeterExecutorGasFallback(req, params.ExecutionGasCostFallback, gasMeter) + MeterExecutorGasFallback(dr, params.TallyConfig.ExecutionGasCostFallback, gasMeter) } else if errors.Is(filterErr, types.ErrInvalidFilterInput) || errors.Is(filterErr, types.ErrNoConsensus) { gasMeter.SetReducedPayoutMode() } @@ -218,6 +187,21 @@ func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, param } tallyResults[i].GasMeter = gasMeter + + err = k.UpdateDataRequestIndexing(ctx, dr.Index(), dr.Status, types.DATA_REQUEST_STATUS_UNSPECIFIED) + if err != nil { + return nil, nil, err + } + // TODO double check + // dr.Status = types.DATA_REQUEST_STATUS_UNSPECIFIED + err = k.RemoveRevealBodies(ctx, dr.ID) + if err != nil { + return nil, nil, err + } + err = k.RemoveDataRequest(ctx, dr.ID) + if err != nil { + return nil, nil, err + } } // Phase 2: Parallel execution of tally VM @@ -259,7 +243,7 @@ func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, param // Calculate data proxy and executor gas consumptions if basic consensus // was reached. if !errors.Is(filterErr, types.ErrNoBasicConsensus) && !errors.Is(filterErr, types.ErrFilterDidNotRun) { - k.MeterProxyGas(ctx, tr.FilterResult.ProxyPubKeys, tr.ReplicationFactor, tr.GasMeter) + k.MeterProxyGas(ctx, tr.FilterResult.ProxyPubKeys, uint64(tr.ReplicationFactor), tr.GasMeter) if areGasReportsUniform(tr.GasReports) { tr.MeterExecutorGasUniform() @@ -273,66 +257,24 @@ func (k Keeper) ProcessTallies(ctx sdk.Context, tallyList []types.Request, param tallyResults[i].TallyGasUsed = tr.GasMeter.TallyGasUsed() tallyResults[i].ExecGasUsed = tr.GasMeter.ExecutionGasUsed() - processedReqs[tr.ID] = k.DistributionsFromGasMeter(ctx, tr.ID, tr.Height, tr.GasMeter, params.BurnRatio) + err = k.ProcessDistributions(ctx, &tr, params.StakingConfig.MinimumStake, params.TallyConfig.BurnRatio) + if err != nil { + return nil, nil, err + } + dataResults[i].GasUsed = tr.GasMeter.TotalGasUsed() } dataResults[i].Id, err = dataResults[i].TryHash() if err != nil { - return nil, nil, nil, err + return nil, nil, err } k.Logger(ctx).Info("completed tally", "request_id", tr.ID) k.Logger(ctx).Debug("tally result", "request_id", tr.ID, "tally_result", tr) } - return tallyResults, dataResults, processedReqs, nil -} - -// queryContract fetches tally-ready data requests from the core contract in batches while -// keeping the interface consistent. This avoids problems where the contract runs out of memory -// when we fetch the entire maxTalliesPerBlock in a single query. -func (k Keeper) queryContract(ctx sdk.Context, coreContract sdk.AccAddress, maxTalliesPerBlock uint32) (*types.ContractListResponse, error) { - tallyList := make([]types.Request, 0, maxTalliesPerBlock) - lastSeenIndex := types.EmptyLastSeenIndex() - isPaused := false - - for { - // The limit is the smaller value between the max number of data requests per query or - // the remaining number that still fits in the block tally limit. - //nolint:gosec // G115: the length of a list should never be negative. - limit := min(MaxDataRequestsPerQuery, maxTalliesPerBlock-uint32(len(tallyList))) - - // Fetch tally-ready data requests. - queryRes, err := k.wasmViewKeeper.QuerySmart( - ctx, coreContract, - fmt.Appendf(nil, `{"get_data_requests_by_status":{"status": "tallying", "last_seen_index": %s, "limit": %d}}`, lastSeenIndex.String(), limit), - ) - if err != nil { - return nil, errorsmod.Wrap(err, "failed to query contract") - } - - var contractQueryResponse types.ContractListResponse - err = json.Unmarshal(queryRes, &contractQueryResponse) - if err != nil { - return nil, errorsmod.Wrap(err, "failed to unmarshal data requests contract response") - } - - lastSeenIndex = contractQueryResponse.LastSeenIndex - isPaused = contractQueryResponse.IsPaused - tallyList = append(tallyList, contractQueryResponse.DataRequests...) - - // Break if we've reached the max number of data requests or if the - // number of data requests returned is less than the limit. - if len(tallyList) >= int(maxTalliesPerBlock) || len(contractQueryResponse.DataRequests) < int(limit) { - break - } - } - - return &types.ContractListResponse{ - IsPaused: isPaused, - DataRequests: tallyList, - }, nil + return tallyResults, dataResults, nil } // areGasReportsUniform returns true if the gas reports of the given reveals are @@ -349,3 +291,10 @@ func areGasReportsUniform(reports []uint64) bool { } return true } + +// logErrAndRet logs the base error along with the request ID for +// debugging and returns the registered error. +func (k Keeper) logErrAndRet(ctx sdk.Context, baseErr, registeredErr error, drID string) error { + k.Logger(ctx).Debug(baseErr.Error(), "request_id", drID, "error", registeredErr) + return registeredErr +} diff --git a/x/tally/types/filter_exec.go b/x/core/keeper/filter.go similarity index 71% rename from x/tally/types/filter_exec.go rename to x/core/keeper/filter.go index 4b03322b..38c65ea6 100644 --- a/x/tally/types/filter_exec.go +++ b/x/core/keeper/filter.go @@ -1,8 +1,9 @@ -package types +package keeper import ( - "encoding/base64" "fmt" + + "github.com/sedaprotocol/seda-chain/x/core/types" ) const ( @@ -23,11 +24,31 @@ type FilterResult struct { Error error } +// countErrors returns the number of errors in a given error list. +func countErrors(errors []bool) int { + count := 0 + for _, err := range errors { + if err { + count++ + } + } + return count +} + +// invertErrors returns an inversion of a given error list. +func invertErrors(errors []bool) []bool { + inverted := make([]bool, len(errors)) + for i, err := range errors { + inverted[i] = !err + } + return inverted +} + // ExecuteFilter builds a filter using the given filter input and applies it to // the given reveals to determine consensus, proxy public keys in consensus, and // outliers. It assumes that the reveals are sorted by their keys and that their // proxy public keys are sorted. -func ExecuteFilter(reveals []Reveal, filterInput string, replicationFactor uint16, params Params, gasMeter *GasMeter) (FilterResult, error) { +func ExecuteFilter(reveals []types.Reveal, filterInput []byte, replicationFactor uint16, params types.TallyConfig, gasMeter *types.GasMeter) (FilterResult, error) { var res FilterResult res.Errors = make([]bool, len(reveals)) res.Outliers = make([]bool, len(reveals)) @@ -48,23 +69,23 @@ func ExecuteFilter(reveals []Reveal, filterInput string, replicationFactor uint1 } if maxFreq*3 < int(replicationFactor)*2 { res.Consensus, res.Outliers = false, nil - return res, ErrNoBasicConsensus + return res, types.ErrNoBasicConsensus } filter, err := BuildFilter(filterInput, replicationFactor, params, gasMeter) if err != nil { res.Consensus, res.Outliers = false, nil - return res, ErrInvalidFilterInput.Wrap(err.Error()) + return res, types.ErrInvalidFilterInput.Wrap(err.Error()) } outliers, consensus := filter.ApplyFilter(reveals, res.Errors) switch { case countErrors(res.Errors)*3 >= len(reveals)*2: res.Consensus, res.Outliers = true, invertErrors(res.Errors) - return res, ErrConsensusInError + return res, types.ErrConsensusInError case !consensus: res.Consensus, res.Outliers = false, nil - return res, ErrNoConsensus + return res, types.ErrNoConsensus default: res.Consensus, res.Outliers = true, outliers return res, nil @@ -72,48 +93,25 @@ func ExecuteFilter(reveals []Reveal, filterInput string, replicationFactor uint1 } // BuildFilter builds a filter based on the requestor-provided input. -func BuildFilter(filterInput string, replicationFactor uint16, params Params, gasMeter *GasMeter) (Filter, error) { - input, err := base64.StdEncoding.DecodeString(filterInput) - if err != nil { - return nil, err - } - if len(input) == 0 { - return nil, ErrInvalidFilterType +func BuildFilter(filterInput []byte, replicationFactor uint16, params types.TallyConfig, gasMeter *types.GasMeter) (types.Filter, error) { + if len(filterInput) == 0 { + return nil, types.ErrInvalidFilterType } - var filter Filter - switch input[0] { + var filter types.Filter + var err error + switch filterInput[0] { case filterTypeNone: - filter, err = NewFilterNone(params.FilterGasCostNone, gasMeter) + filter, err = types.NewFilterNone(params.FilterGasCostNone, gasMeter) case filterTypeMode: - filter, err = NewFilterMode(input, params.FilterGasCostMultiplierMode, replicationFactor, gasMeter) + filter, err = types.NewFilterMode(filterInput, params.FilterGasCostMultiplierMode, replicationFactor, gasMeter) case filterTypeMAD: - filter, err = NewFilterMAD(input, params.FilterGasCostMultiplierMAD, replicationFactor, gasMeter) + filter, err = types.NewFilterMAD(filterInput, params.FilterGasCostMultiplierMAD, replicationFactor, gasMeter) default: - return nil, ErrInvalidFilterType + return nil, types.ErrInvalidFilterType } if err != nil { return nil, err } return filter, nil } - -// countErrors returns the number of errors in a given error list. -func countErrors(errors []bool) int { - count := 0 - for _, err := range errors { - if err { - count++ - } - } - return count -} - -// invertErrors returns an inversion of a given error list. -func invertErrors(errors []bool) []bool { - inverted := make([]bool, len(errors)) - for i, err := range errors { - inverted[i] = !err - } - return inverted -} diff --git a/x/tally/keeper/filter_and_tally_test.go b/x/core/keeper/filter_and_tally_test.go similarity index 64% rename from x/tally/keeper/filter_and_tally_test.go rename to x/core/keeper/filter_and_tally_test.go index 8b62cd54..0ad5ec70 100644 --- a/x/tally/keeper/filter_and_tally_test.go +++ b/x/core/keeper/filter_and_tally_test.go @@ -1,7 +1,7 @@ package keeper_test +/* Turned off until x/core endblock implementation is complete import ( - "encoding/base64" "encoding/hex" "fmt" "slices" @@ -14,8 +14,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sedaprotocol/seda-chain/testutil/testwasms" + "github.com/sedaprotocol/seda-chain/x/core/types" dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" - "github.com/sedaprotocol/seda-chain/x/tally/types" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" ) @@ -23,8 +23,9 @@ func TestFilterAndTally(t *testing.T) { f := initFixture(t) defaultParams := types.DefaultParams() - err := f.tallyKeeper.SetParams(f.Context(), defaultParams) + err := f.keeper.SetParams(f.Context(), defaultParams) require.NoError(t, err) + tallyConfig := defaultParams.TallyConfig tests := []struct { name string @@ -43,15 +44,15 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "00", outliers: []bool{false, false, false, false}, reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, }, replicationFactor: 5, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostNone, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostNone, exitCode: types.TallyExitCodeExecError, // since tally program does not exist filterErr: nil, }, @@ -60,12 +61,12 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "00", outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, }, replicationFactor: 5, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase, + tallyGasUsed: tallyConfig.GasCostBase, exitCode: types.TallyExitCodeFilterError, filterErr: types.ErrNoBasicConsensus, }, @@ -74,15 +75,15 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, false, false}, reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, }, replicationFactor: 5, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*5, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*5, exitCode: types.TallyExitCodeExecError, // since tally program does not exist filterErr: nil, }, @@ -91,12 +92,12 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`)}, }, replicationFactor: 5, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase, + tallyGasUsed: tallyConfig.GasCostBase, exitCode: types.TallyExitCodeFilterError, filterErr: types.ErrNoBasicConsensus, }, @@ -105,16 +106,16 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "02000000000016E36001000000000000000D242E726573756C742E74657874", // max_sigma = 1.5, number_type = int64, json_path = $.result.text outliers: []bool{false, false, false, false, false}, // MaxDev = 1*1.5 = 1.5, Median = 5 reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": 5}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 6}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 4}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 6}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 5}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 5}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 6}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 4}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 6}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 5}}`)}, }, replicationFactor: 6, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, exitCode: types.TallyExitCodeExecError, // since tally program does not exist filterErr: nil, }, @@ -123,16 +124,16 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "02000000000016E36001000000000000000D242E726573756C742E74657874", // max_sigma = 1.5, number_type = int64, json_path = $.result.text outliers: []bool{false, false, false, false, true}, // MaxDev = 1*1.5 = 1.5, Median = 5 reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": 5}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 6}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 4}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 6}}`}, - {ExitCode: 0, Reveal: `{"result": {"text": 1}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 5}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 6}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 4}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 6}}`)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 1}}`)}, }, replicationFactor: 5, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*5, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*5, exitCode: types.TallyExitCodeExecError, // since tally program does not exist filterErr: nil, }, @@ -141,12 +142,12 @@ func TestFilterAndTally(t *testing.T) { tallyInputAsHex: "02000000000016E36001000000000000000D242E726573756C742E74657874", // max_sigma = 1.5, number_type = int64, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, Reveal: `{"result": {"text": 5}}`}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": 5}}`)}, }, replicationFactor: 5, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase, + tallyGasUsed: tallyConfig.GasCostBase, exitCode: types.TallyExitCodeFilterError, filterErr: types.ErrNoBasicConsensus, }, @@ -156,17 +157,27 @@ func TestFilterAndTally(t *testing.T) { filterInput, err := hex.DecodeString(tt.tallyInputAsHex) require.NoError(t, err) + drID := "id" + reveals := make(map[string]types.RevealBody) commits := make(map[string][]byte) + revealsMap := make(map[string]bool) expectedOutliers := make(map[string]bool) for i, v := range tt.reveals { + executor := fmt.Sprintf("%d", i) + revealsMap[executor] = true + revealBody := v - revealBody.Reveal = base64.StdEncoding.EncodeToString([]byte(v.Reveal)) + revealBody.DrId = drID + revealBody.Reveal = v.Reveal revealBody.GasUsed = v.GasUsed - reveals[fmt.Sprintf("%d", i)] = revealBody + reveals[executor] = revealBody if tt.outliers != nil { - expectedOutliers[fmt.Sprintf("%d", i)] = tt.outliers[i] + expectedOutliers[executor] = tt.outliers[i] } + + err = f.keeper.SetRevealBody(f.Context(), executor, revealBody) + require.NoError(t, err) } // To avoid commit timeout (no other effect intended) @@ -174,9 +185,9 @@ func TestFilterAndTally(t *testing.T) { commits[fmt.Sprintf("executor-%d", i)] = []byte{} } - tallyRes, dataRes, processedReqs, err := f.tallyKeeper.ProcessTallies( + tallyRes, dataRes, processedReqs, err := f.keeper.ProcessTallies( f.Context(), - []types.Request{ + []types.DataRequest{ { Commits: commits, Reveals: reveals, @@ -188,7 +199,7 @@ func TestFilterAndTally(t *testing.T) { // TallyProgramID: hex.EncodeToString(tallyProgram.Hash), // skip tally program execution }, }, - types.DefaultParams(), false) + tallyConfig, false) require.NoError(t, err) require.Equal(t, 1, len(tallyRes)) @@ -228,8 +239,8 @@ func TestFilterAndTally(t *testing.T) { func TestExecutorPayout(t *testing.T) { f := initFixture(t) - defaultParams := types.DefaultParams() - err := f.tallyKeeper.SetParams(f.Context(), defaultParams) + tallyConfig := types.DefaultParams() + err := f.keeper.SetParams(f.Context(), tallyConfig) require.NoError(t, err) tallyProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm2(), f.Context().BlockTime()) @@ -247,7 +258,7 @@ func TestExecutorPayout(t *testing.T) { tallyInputAsHex string reveals map[string]types.RevealBody requestID string - replicationFactor uint16 + replicationFactor uint32 execGasLimit uint64 expExecGasUsed uint64 expReducedPayout bool @@ -258,9 +269,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -275,9 +286,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting beyond execGasLimit", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, }, replicationFactor: 3, execGasLimit: 60000, @@ -292,9 +303,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting (consensus with 1 outlier)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 30000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 30000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -308,9 +319,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting (mode consensus in error)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 1, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "b": {ExitCode: 1, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 30000}, + "a": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "b": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 30000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -325,9 +336,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting (mode no consensus)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 20000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 20000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, }, replicationFactor: 3, execGasLimit: 60000, @@ -343,9 +354,9 @@ func TestExecutorPayout(t *testing.T) { name: "Uniform gas reporting with low gas limit (mode no consensus)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 20000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 20000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, }, replicationFactor: 3, execGasLimit: 1000, @@ -361,9 +372,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (low*2 > median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -378,11 +389,11 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with multiple lows (low*2 > median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "lizard": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, - "bonobo": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "penguin": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, - "zebra": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, - "lion": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, + "lizard": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, + "bonobo": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "penguin": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, + "zebra": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, + "lion": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, }, requestID: "646174615F726571756573745F31", replicationFactor: 5, @@ -400,11 +411,11 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with multiple lows, different req ID (low*2 > median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "lizard": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, - "bonobo": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 30000}, - "penguin": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, - "zebra": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, - "lion": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, + "lizard": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, + "bonobo": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 30000}, + "penguin": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, + "zebra": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, + "lion": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, }, requestID: "646174615F726571756573745F35", replicationFactor: 5, @@ -422,9 +433,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with multiple lows (low*2 > median, low is median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 30000, @@ -439,9 +450,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (low*2 < median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 20000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 20000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -456,9 +467,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with multiple lows (low*2 < median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 10000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 10000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, }, replicationFactor: 3, execGasLimit: 50000, @@ -473,11 +484,11 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (low*2 < median)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "zebra": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 32000}, - "lizard": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 20000}, - "bonobo": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 35000}, - "penguin": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "lion": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 28000}, + "zebra": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 32000}, + "lizard": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 20000}, + "bonobo": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 35000}, + "penguin": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "lion": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 28000}, }, replicationFactor: 5, execGasLimit: 200000, @@ -494,9 +505,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (lowest_report*2 == median_report)", tallyInputAsHex: "00", reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 10000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 20000}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 10000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 20000}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -511,9 +522,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (mode no consensus)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 90000, @@ -529,9 +540,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with low gas limit and no shares (mode no consensus)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 1}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 1}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 1000, @@ -547,9 +558,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with low gas limit and shares (mode no consensus)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000}, }, replicationFactor: 3, execGasLimit: 1000, @@ -565,9 +576,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (mode no consensus, with 1 proxy)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ // (7000, 19000, 34000) after subtracting proxy gas - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0]}}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0]}}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0]}}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0]}}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, }, replicationFactor: 3, execGasLimit: 90000, @@ -586,9 +597,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting (consensus with 1 outlier, with 2 proxies)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ // (6000, 18000, 33000) after subtracting proxy gas - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, }, replicationFactor: 3, execGasLimit: 90000, @@ -607,9 +618,9 @@ func TestExecutorPayout(t *testing.T) { name: "Divergent gas reporting with low gas limit (mode no consensus, with 2 proxies)", tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // mode, json_path = $.result.text reveals: map[string]types.RevealBody{ // (0, 0, 0) after subtracting proxy gas and considering gas limit - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "B"}}`, GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, - "c": {ExitCode: 1, Reveal: `{"result": {"text": "B"}}`, GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: 8000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 20000, ProxyPubKeys: []string{pubKeys[0], pubKeys[1]}}, + "c": {ExitCode: 1, Reveal: []byte(`{"result": {"text": "B"}}`), GasUsed: 35000, ProxyPubKeys: []string{pubKeys[0]}}, }, replicationFactor: 3, execGasLimit: 1000, @@ -629,14 +640,14 @@ func TestExecutorPayout(t *testing.T) { name: "MAD uint128 (1 reveal missing, consensus with 2 outliers, uniform gas reporting)", tallyInputAsHex: "0200000000002DC6C005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 3, number_type = 0x05, json_path = $.result.text reveals: map[string]types.RevealBody{ // median = 400000, MAD = 50000 - "a": {Reveal: `{"result": {"text": 300000, "number": 0}}`, GasUsed: 25000}, - "b": {Reveal: `{"result": {"number": 700000, "number": 0}}`, GasUsed: 25000}, // corrupt - "c": {Reveal: `{"result": {"text": 400000, "number": 10}}`, GasUsed: 25000}, - "d": {Reveal: `{"result": {"text": 400000, "number": 101}}`, GasUsed: 25000}, - "e": {Reveal: `{"result": {"text": 400000, "number": 0}}`, GasUsed: 25000}, - "f": {Reveal: `{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`, GasUsed: 25000}, // overflow - "g": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 25000}, - "h": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 25000}, + "a": {Reveal: []byte(`{"result": {"text": 300000, "number": 0}}`), GasUsed: 25000}, + "b": {Reveal: []byte(`{"result": {"number": 700000, "number": 0}}`), GasUsed: 25000}, // corrupt + "c": {Reveal: []byte(`{"result": {"text": 400000, "number": 10}}`), GasUsed: 25000}, + "d": {Reveal: []byte(`{"result": {"text": 400000, "number": 101}}`), GasUsed: 25000}, + "e": {Reveal: []byte(`{"result": {"text": 400000, "number": 0}}`), GasUsed: 25000}, + "f": {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`), GasUsed: 25000}, // overflow + "g": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 25000}, + "h": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 25000}, }, replicationFactor: 9, execGasLimit: 900000, @@ -654,14 +665,14 @@ func TestExecutorPayout(t *testing.T) { name: "MAD uint128 (1 reveal missing, consensus with 2 outliers, divergent gas reporting)", tallyInputAsHex: "0200000000002DC6C005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 3, number_type = 0x05, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {Reveal: `{"result": {"text": 300000, "number": 0}}`, GasUsed: 25000}, - "b": {Reveal: `{"result": {"number": 700000, "number": 0}}`, GasUsed: 27000}, // corrupt - "c": {Reveal: `{"result": {"text": 400000, "number": 10}}`, GasUsed: 21500}, - "d": {Reveal: `{"result": {"text": 400000, "number": 101}}`, GasUsed: 29000}, - "e": {Reveal: `{"result": {"text": 400000, "number": 0}}`, GasUsed: 35000}, - "f": {Reveal: `{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`, GasUsed: 400}, // overflow - "g": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 29800}, - "h": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 25000}, + "a": {Reveal: []byte(`{"result": {"text": 300000, "number": 0}}`), GasUsed: 25000}, + "b": {Reveal: []byte(`{"result": {"number": 700000, "number": 0}}`), GasUsed: 27000}, // corrupt + "c": {Reveal: []byte(`{"result": {"text": 400000, "number": 10}}`), GasUsed: 21500}, + "d": {Reveal: []byte(`{"result": {"text": 400000, "number": 101}}`), GasUsed: 29000}, + "e": {Reveal: []byte(`{"result": {"text": 400000, "number": 0}}`), GasUsed: 35000}, + "f": {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`), GasUsed: 400}, // overflow + "g": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 29800}, + "h": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 25000}, }, replicationFactor: 9, execGasLimit: 900000, @@ -679,14 +690,14 @@ func TestExecutorPayout(t *testing.T) { name: "MAD uint128 (1 reveal missing, consensus with 2 outliers, divergent gas reporting)", tallyInputAsHex: "0200000000002DC6C005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 3, number_type = 0x05, json_path = $.result.text reveals: map[string]types.RevealBody{ - "a": {Reveal: `{"result": {"text": 300000, "number": 0}}`, GasUsed: 25000}, - "b": {Reveal: `{"result": {"number": 700000, "number": 0}}`, GasUsed: 27000}, // corrupt - "c": {Reveal: `{"result": {"text": 400000, "number": 10}}`, GasUsed: 21500}, - "d": {Reveal: `{"result": {"text": 400000, "number": 101}}`, GasUsed: 29000}, - "e": {Reveal: `{"result": {"text": 400000, "number": 0}}`, GasUsed: 35000}, - "f": {Reveal: `{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`, GasUsed: 29800}, // overflow - "g": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 400}, - "h": {Reveal: `{"result": {"text": 500000, "number": 0}}`, GasUsed: 25000}, + "a": {Reveal: []byte(`{"result": {"text": 300000, "number": 0}}`), GasUsed: 25000}, + "b": {Reveal: []byte(`{"result": {"number": 700000, "number": 0}}`), GasUsed: 27000}, // corrupt + "c": {Reveal: []byte(`{"result": {"text": 400000, "number": 10}}`), GasUsed: 21500}, + "d": {Reveal: []byte(`{"result": {"text": 400000, "number": 101}}`), GasUsed: 29000}, + "e": {Reveal: []byte(`{"result": {"text": 400000, "number": 0}}`), GasUsed: 35000}, + "f": {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`), GasUsed: 29800}, // overflow + "g": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 400}, + "h": {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`), GasUsed: 25000}, }, replicationFactor: 9, execGasLimit: 900000, @@ -710,12 +721,17 @@ func TestExecutorPayout(t *testing.T) { require.True(t, ok) proxyFee := sdk.NewCoin(bondDenom, exp21) commits := make(map[string][]byte) - reveals := make(map[string]types.RevealBody) + revealsMap := make(map[string]bool) for k, v := range tt.reveals { + revealsMap[k] = true + revealBody := v - revealBody.Reveal = base64.StdEncoding.EncodeToString([]byte(v.Reveal)) + revealBody.DrId = tt.requestID + revealBody.Reveal = v.Reveal revealBody.GasUsed = v.GasUsed - reveals[k] = revealBody + + err = f.keeper.SetRevealBody(f.Context(), k, revealBody) + require.NoError(t, err) for _, pk := range v.ProxyPubKeys { pkBytes, err := hex.DecodeString(pk) @@ -736,12 +752,11 @@ func TestExecutorPayout(t *testing.T) { commits[fmt.Sprintf("executor-%d", i)] = []byte{} } - request := types.Request{ - Commits: commits, - Reveals: reveals, + request := types.DataRequest{ + Reveals: revealsMap, ReplicationFactor: tt.replicationFactor, - ConsensusFilter: base64.StdEncoding.EncodeToString(filterInput), - PostedGasPrice: "1000000000000000000", // 1e18 + ConsensusFilter: filterInput, + PostedGasPrice: math.NewIntWithDecimal(1, 18), TallyGasLimit: types.DefaultMaxTallyGasLimit, ExecGasLimit: tt.execGasLimit, TallyProgramID: hex.EncodeToString(tallyProgram.Hash), @@ -750,7 +765,7 @@ func TestExecutorPayout(t *testing.T) { request.ID = tt.requestID } - tallyRes, dataRes, processedReqs, err := f.tallyKeeper.ProcessTallies(f.Context(), []types.Request{request}, types.DefaultParams(), false) + tallyRes, dataRes, processedReqs, err := f.keeper.ProcessTallies(f.Context(), []string{request.ID}, types.DefaultParams().TallyConfig, false) require.NoError(t, err) require.Equal(t, 1, len(tallyRes)) @@ -780,3 +795,4 @@ func TestExecutorPayout(t *testing.T) { }) } } +*/ diff --git a/x/tally/keeper/filter_test.go b/x/core/keeper/filter_test.go similarity index 60% rename from x/tally/keeper/filter_test.go rename to x/core/keeper/filter_test.go index 837e75d6..45c7068d 100644 --- a/x/tally/keeper/filter_test.go +++ b/x/core/keeper/filter_test.go @@ -1,7 +1,6 @@ package keeper_test import ( - "encoding/base64" "encoding/hex" "fmt" "sort" @@ -11,16 +10,19 @@ import ( "cosmossdk.io/math" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/keeper" + "github.com/sedaprotocol/seda-chain/x/core/types" ) func TestFilter(t *testing.T) { f := initFixture(t) defaultParams := types.DefaultParams() - err := f.tallyKeeper.SetParams(f.Context(), defaultParams) + err := f.keeper.SetParams(f.Context(), defaultParams) require.NoError(t, err) + tallyConfig := defaultParams.TallyConfig + tests := []struct { name string tallyInputAsHex string @@ -44,7 +46,7 @@ func TestFilter(t *testing.T) { }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostNone, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostNone, wantErr: nil, }, { @@ -52,17 +54,17 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, true, false, true, false, false}, reveals: []types.RevealBody{ - {Reveal: `{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`}, - {Reveal: `{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`}, - {Reveal: `{"but":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`}, - {Reveal: `{"matter":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"matter":"ignore this", "result": {"text": "A", "number": 10}}`}, + {Reveal: []byte(`{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`)}, + {Reveal: []byte(`{"but":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`)}, + {Reveal: []byte(`{"matter":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"matter":"ignore this", "result": {"text": "A", "number": 10}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: nil, }, { @@ -70,13 +72,13 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, true}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": "A", "number": 0}}`}, - {Reveal: `{"result": {"text": "A", "number": 10}}`}, - {Reveal: `{"result": {"text": "B", "number": 101}}`}, + {Reveal: []byte(`{"result": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "B", "number": 101}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*3, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*3, wantErr: nil, }, { @@ -84,13 +86,13 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, true}, reveals: []types.RevealBody{ - {ExitCode: 1, Reveal: ``}, - {ExitCode: 2, Reveal: ``}, - {ExitCode: 0, Reveal: `{"result": {"text": "A", "number": 0}}`}, + {ExitCode: 1, Reveal: []byte(``)}, + {ExitCode: 2, Reveal: []byte(``)}, + {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A", "number": 0}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*3, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*3, wantErr: types.ErrConsensusInError, }, { @@ -98,17 +100,17 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": "A"}}`}, - {Reveal: `{"result": {"text": "A"}}`}, - {Reveal: `{"result": {"text": "A"}}`}, - {Reveal: `{"result": {"text": "B"}}`}, - {Reveal: `{"result": {"text": "B"}}`}, - {Reveal: `{"result": {"text": "B"}}`}, - {Reveal: `{"result": {"text": "C"}}`}, + {Reveal: []byte(`{"result": {"text": "A"}}`)}, + {Reveal: []byte(`{"result": {"text": "A"}}`)}, + {Reveal: []byte(`{"result": {"text": "A"}}`)}, + {Reveal: []byte(`{"result": {"text": "B"}}`)}, + {Reveal: []byte(`{"result": {"text": "B"}}`)}, + {Reveal: []byte(`{"result": {"text": "B"}}`)}, + {Reveal: []byte(`{"result": {"text": "C"}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: types.ErrNoConsensus, }, { @@ -116,13 +118,13 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, true, false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": "A", "number": 0}}`}, - {Reveal: `{"resultt": {"text": "A", "number": 10}}`}, - {Reveal: `{"result": {"text": "A", "number": 101}}`}, + {Reveal: []byte(`{"result": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"resultt": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 101}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*3, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*3, wantErr: nil, }, { @@ -130,16 +132,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 1, Reveal: `{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`}, - {ExitCode: 1, Reveal: `{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`}, - {ExitCode: 1, Reveal: `{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`}, - {ExitCode: 0, Reveal: `{"but":"ignore this", "result": {"text": "B", "number": 10}}`}, - {ExitCode: 0, Reveal: `{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`}, - {ExitCode: 0, Reveal: `{"matter":"ignore this", "result": {"text": "C", "number": 10}}`}, + {ExitCode: 1, Reveal: []byte(`{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`)}, + {ExitCode: 1, Reveal: []byte(`{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {ExitCode: 1, Reveal: []byte(`{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`)}, + {ExitCode: 0, Reveal: []byte(`{"but":"ignore this", "result": {"text": "B", "number": 10}}`)}, + {ExitCode: 0, Reveal: []byte(`{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`)}, + {ExitCode: 0, Reveal: []byte(`{"matter":"ignore this", "result": {"text": "C", "number": 10}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + 0, + tallyGasUsed: tallyConfig.GasCostBase + 0, wantErr: types.ErrNoBasicConsensus, }, { @@ -147,16 +149,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, false, false, true, false}, reveals: []types.RevealBody{ - {ExitCode: 1, Reveal: `{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`}, - {ExitCode: 1, Reveal: `{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`}, - {ExitCode: 1, Reveal: `{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`}, - {ExitCode: 1, Reveal: `{"but":"ignore this", "result": {"text": "B", "number": 10}}`}, - {ExitCode: 0, Reveal: `{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`}, - {ExitCode: 1, Reveal: `{"matter":"ignore this", "result": {"text": "C", "number": 10}}`}, + {ExitCode: 1, Reveal: []byte(`{"high_level_prop1":"ignore this", "result": {"text": "A", "number": 0}}`)}, + {ExitCode: 1, Reveal: []byte(`{"makes_this_json":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {ExitCode: 1, Reveal: []byte(`{"unstructured":"ignore this", "result": {"text": "B", "number": 101}}`)}, + {ExitCode: 1, Reveal: []byte(`{"but":"ignore this", "result": {"text": "B", "number": 10}}`)}, + {ExitCode: 0, Reveal: []byte(`{"it_does_not":"ignore this", "result": {"text": "C", "number": 10}}`)}, + {ExitCode: 1, Reveal: []byte(`{"matter":"ignore this", "result": {"text": "C", "number": 10}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*6, wantErr: types.ErrConsensusInError, }, { @@ -172,7 +174,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -182,7 +184,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -192,7 +194,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -202,7 +204,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -212,7 +214,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -222,7 +224,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, }, consensus: true, @@ -232,7 +234,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*6, wantErr: nil, }, { @@ -248,7 +250,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -257,7 +259,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 1, @@ -267,7 +269,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 1, @@ -277,7 +279,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 1, @@ -287,7 +289,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 1, @@ -297,7 +299,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, }, consensus: true, @@ -307,7 +309,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*6, wantErr: types.ErrConsensusInError, }, { @@ -323,7 +325,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -332,12 +334,12 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, ProxyPubKeys: []string{}, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -347,7 +349,7 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -357,7 +359,7 @@ func TestFilter(t *testing.T) { "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4c3", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, { ExitCode: 0, @@ -367,12 +369,12 @@ func TestFilter(t *testing.T) { "02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3", "034c0f86f0cb61f9ddb47c4ba0b2ca0470962b5a1c50bee3a563184979672195f4", }, - Reveal: `{"result": {"text": "A"}}`, + Reveal: []byte(`{"result": {"text": "A"}}`), }, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + 0, + tallyGasUsed: tallyConfig.GasCostBase + 0, wantErr: types.ErrNoBasicConsensus, }, { @@ -380,14 +382,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{false, false, true, false}, reveals: []types.RevealBody{ - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"invalid_proxy_pubkey"}, Reveal: `{"result": {"text": "mac"}}`}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"invalid_proxy_pubkey"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, }, consensus: true, consPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*4, wantErr: nil, }, { @@ -395,14 +397,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 1, ProxyPubKeys: []string{"invalid_proxy_pubkey"}, Reveal: `{"result": {"text": "mac"}}`}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 1, ProxyPubKeys: []string{"invalid_proxy_pubkey"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, }, consensus: false, consPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*4, wantErr: types.ErrNoConsensus, }, { @@ -410,14 +412,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": ""}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": ""}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, }, consensus: false, consPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*4, wantErr: types.ErrNoConsensus, }, { @@ -425,14 +427,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: []bool{true, false, false, false}, reveals: []types.RevealBody{ - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"qwerty"}, Reveal: `{"result": {"text": "windows"}}`}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"qwerty"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, }, consensus: true, consPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*4, wantErr: nil, }, { @@ -440,14 +442,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "mac"}}`}, - {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, - {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: `{"result": {"text": "windows"}}`}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "mac"}}`)}, + {ExitCode: 0, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, + {ExitCode: 1, ProxyPubKeys: []string{"02100efce2a783cc7a3fbf9c5d15d4cc6e263337651312f21a35d30c16cb38f4g3"}, Reveal: []byte(`{"result": {"text": "windows"}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + 0, + tallyGasUsed: tallyConfig.GasCostBase + 0, wantErr: types.ErrNoBasicConsensus, }, { @@ -457,18 +459,18 @@ func TestFilter(t *testing.T) { reveals: []types.RevealBody{ { ExitCode: 1, - Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 0}}`, + Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 0}}`), }, - {Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 101}}`}, - {Reveal: `{"xx":"ignore this", "result": {"text": "B", "number": 10}}`}, - {Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 10}}`}, - {Reveal: `{"xx":"ignore this", "result": {"text": "A", "number": 10}}`}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 101}}`)}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "B", "number": 10}}`)}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"xx":"ignore this", "result": {"text": "A", "number": 10}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: nil, }, { @@ -476,16 +478,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": "A", "number": 0}}`, ExitCode: 1}, - {Reveal: `{"result": {"text": "A", "number": 0}}`}, - {Reveal: `{"result": {"text": "A", "number": 0}}`}, - {Reveal: `{"result": {"text": "B", "number": 10}}`}, - {Reveal: `{"result": {"text": "C", "number": 10}}`}, - {Reveal: `{"result": {"text": "A", "number": 10}}`}, + {Reveal: []byte(`{"result": {"text": "A", "number": 0}}`), ExitCode: 1}, + {Reveal: []byte(`{"result": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": "B", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "C", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 10}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*6, wantErr: types.ErrNoConsensus, }, { @@ -493,16 +495,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000D242E726573756C742E74657874", // json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"resalt": {"text": "A", "number": 0}}`}, - {Reveal: `{"result": {"text": "A", "number": 10}}`}, - {Reveal: `{"result": {"text": "A", "number": 101}}`}, - {Reveal: `{"result": {"text": "B", "number": 10}}`}, - {Reveal: `{"result": {"text": "C", "number": 10}}`}, - {Reveal: `{"result": {"text": "A", "number": 10}}`}, + {Reveal: []byte(`{"resalt": {"text": "A", "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": "B", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "C", "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": "A", "number": 10}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*6, wantErr: types.ErrNoConsensus, }, { @@ -510,14 +512,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000016E36006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.5, number_type = 0x00, json_path = $.result.text outliers: []bool{false, false, false, false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 0}}`}, - {Reveal: `{"result": {"text": 0}}`}, - {Reveal: `{"result": {"text": 0}}`}, - {Reveal: `{"result": {"text": 0}}`}, + {Reveal: []byte(`{"result": {"text": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 0}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: nil, }, { @@ -525,17 +527,17 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000016E36006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.5, number_type = 0x00, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 1000}}`}, - {Reveal: `{"result": {"text": 1000}}`}, - {Reveal: `{"result": {"text": 115792089237316195423570985008687907853269}}`}, - {Reveal: `{"result": {"text": 5000}}`}, - {Reveal: `{"result": {"text": 5500}}`}, - {Reveal: `{"result": {"text": 5400}}`}, - {Reveal: `{"result": {"text": 5300}}`}, + {Reveal: []byte(`{"result": {"text": 1000}}`)}, + {Reveal: []byte(`{"result": {"text": 1000}}`)}, + {Reveal: []byte(`{"result": {"text": 115792089237316195423570985008687907853269}}`)}, + {Reveal: []byte(`{"result": {"text": 5000}}`)}, + {Reveal: []byte(`{"result": {"text": 5500}}`)}, + {Reveal: []byte(`{"result": {"text": 5400}}`)}, + {Reveal: []byte(`{"result": {"text": 5300}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*7, wantErr: types.ErrNoConsensus, }, { @@ -543,16 +545,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x01, json_path = $.result.text outliers: []bool{true, false, false, true, false, false}, reveals: []types.RevealBody{ // median = 6.5, MAD = 1.5, max_dev = 1.5 - {Reveal: `{"result": {"text": 4}}`}, // outlier - {Reveal: `{"result": {"text": 5}}`}, - {Reveal: `{"result": {"text": 6}}`}, - {Reveal: `{"result": {"text": 9}}`}, // outlier - {Reveal: `{"result": {"text": 7}}`}, - {Reveal: `{"result": {"text": 8}}`}, + {Reveal: []byte(`{"result": {"text": 4}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": 5}}`)}, + {Reveal: []byte(`{"result": {"text": 6}}`)}, + {Reveal: []byte(`{"result": {"text": 9}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": 7}}`)}, + {Reveal: []byte(`{"result": {"text": 8}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -560,14 +562,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x01, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 4294967295}}`}, // ok (max of uint64) - {Reveal: `{"result": {"text": 4294967296}}`}, // overflow - {Reveal: `{"result": {"text": 4294967295}}`}, // ok - {Reveal: `{"result": {"text": -100, "number": 0}}`}, // negative + {Reveal: []byte(`{"result": {"text": 4294967295}}`)}, // ok (max of uint64) + {Reveal: []byte(`{"result": {"text": 4294967296}}`)}, // overflow + {Reveal: []byte(`{"result": {"text": 4294967295}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -100, "number": 0}}`)}, // negative }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: types.ErrNoConsensus, }, { @@ -575,14 +577,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x03, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 18446744073709551615}}`}, // ok (max of uint64) - {Reveal: `{"result": {"text": 18446744073709551616}}`}, // overflow - {Reveal: `{"result": {"text": 18446744073709551615}}`}, // ok - {Reveal: `{"result": {"text": -100, "number": 0}}`}, // negative + {Reveal: []byte(`{"result": {"text": 18446744073709551615}}`)}, // ok (max of uint64) + {Reveal: []byte(`{"result": {"text": 18446744073709551616}}`)}, // overflow + {Reveal: []byte(`{"result": {"text": 18446744073709551615}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -100, "number": 0}}`)}, // negative }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: types.ErrNoConsensus, }, { @@ -590,14 +592,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x05, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 340282366920938463463374607431768211455}}`}, // ok (max of uint128) - {Reveal: `{"result": {"text": 340282366920938463463374607431768211456}}`}, // overflow - {Reveal: `{"result": {"text": 340282366920938463463374607431768211455}}`}, // ok - {Reveal: `{"result": {"text": -100, "number": 0}}`}, // negative + {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211455}}`)}, // ok (max of uint128) + {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211456}}`)}, // overflow + {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211455}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -100, "number": 0}}`)}, // negative }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: types.ErrNoConsensus, }, { @@ -605,16 +607,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000001E848002000000000000000D242E726573756C742E74657874", // sigma_multiplier = 2.0, number_type = 0x02, json_path = $.result.text outliers: []bool{false, false, false, false, true, true}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 4}}`}, - {Reveal: `{"result": {"text": 5}}`}, - {Reveal: `{"result": {"text": 6}}`}, - {Reveal: `{"result": {"text": 7}}`}, - {Reveal: `{"result": {"text": -9223372036854775809}}`}, // overflow - {Reveal: `{"result": {"text": 9}}`}, + {Reveal: []byte(`{"result": {"text": 4}}`)}, + {Reveal: []byte(`{"result": {"text": 5}}`)}, + {Reveal: []byte(`{"result": {"text": 6}}`)}, + {Reveal: []byte(`{"result": {"text": 7}}`)}, + {Reveal: []byte(`{"result": {"text": -9223372036854775809}}`)}, // overflow + {Reveal: []byte(`{"result": {"text": 9}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -622,11 +624,11 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000016E36001000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.5, number_type = 0x01, json_path = $.result.text outliers: []bool{false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 4, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": 4, "number": 0}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD, wantErr: nil, }, { @@ -634,16 +636,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000001E848000000000000000000D242E726573756C742E74657874", // sigma_multiplier = 2.0, number_type = 0x00, json_path = $.result.text outliers: []bool{false, false, false, false, false, true}, reveals: []types.RevealBody{ // median = 6, MAD = 1, max_dev = 2 => [4,8] - {Reveal: `{"result": {"text": 4}}`}, - {Reveal: `{"result": {"text": 5}}`}, - {Reveal: `{"result": {"text": 6}}`}, - {Reveal: `{"result": {"text": 7}}`}, - {Reveal: `{"result": {"text": 6}}`}, - {Reveal: `{"result": {"text": 2147483648}}`}, // overflow + {Reveal: []byte(`{"result": {"text": 4}}`)}, + {Reveal: []byte(`{"result": {"text": 5}}`)}, + {Reveal: []byte(`{"result": {"text": 6}}`)}, + {Reveal: []byte(`{"result": {"text": 7}}`)}, + {Reveal: []byte(`{"result": {"text": 6}}`)}, + {Reveal: []byte(`{"result": {"text": 2147483648}}`)}, // overflow }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -651,16 +653,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000001E848000000000000000000D242E726573756C742E74657874", // sigma_multiplier = 2.0, number_type = 0x00, json_path = $.result.text outliers: []bool{false, false, false, false, false, false}, reveals: []types.RevealBody{ // median = -6.5, MAD = 1.5, max_dev = 3 => [-9.5, -3.5] - {Reveal: `{"result": {"text": -4, "number": 0}}`}, - {Reveal: `{"result": {"text": -5, "number": 10}}`}, - {Reveal: `{"result": {"text": -6, "number": 101}}`}, - {Reveal: `{"result": {"text": -7, "number": 0}}`}, - {Reveal: `{"result": {"text": -8, "number": 0}}`}, - {Reveal: `{"result": {"text": -9, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": -4, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -5, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": -6, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": -7, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -8, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -9, "number": 0}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -668,16 +670,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424000000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x00, json_path = $.result.text outliers: []bool{true, false, false, false, false, true}, reveals: []types.RevealBody{ // median = -6.5, MAD = 1.5, max_dev = 1.5 => [-8, -5] - {Reveal: `{"result": {"text": -4, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": -5, "number": 10}}`}, - {Reveal: `{"result": {"text": -6, "number": 101}}`}, - {Reveal: `{"result": {"text": -7, "number": 0}}`}, - {Reveal: `{"result": {"text": -8, "number": 0}}`}, - {Reveal: `{"result": {"text": -9, "number": 0}}`}, // outlier + {Reveal: []byte(`{"result": {"text": -4, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -5, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": -6, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": -7, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -8, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -9, "number": 0}}`)}, // outlier }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -685,18 +687,18 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000002DC6C005000000000000000D242E726573756C742E74657874", // sigma_multiplier = 3, number_type = 0x05, json_path = $.result.text outliers: []bool{false, true, false, false, false, true, false, false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 300000, "number": 0}}`}, - {Reveal: `{"result": {"number": 700000, "number": 0}}`}, // corrupt - {Reveal: `{"result": {"text": 400000, "number": 10}}`}, - {Reveal: `{"result": {"text": 400000, "number": 101}}`}, - {Reveal: `{"result": {"text": 400000, "number": 0}}`}, - {Reveal: `{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`}, // overflow - {Reveal: `{"result": {"text": 500000, "number": 0}}`}, - {Reveal: `{"result": {"text": 500000, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": 300000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"number": 700000, "number": 0}}`)}, // corrupt + {Reveal: []byte(`{"result": {"text": 400000, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": 400000, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": 400000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 340282366920938463463374607431768211456, "number": 0}}`)}, // overflow + {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 500000, "number": 0}}`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*8, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*8, wantErr: nil, }, { @@ -704,18 +706,18 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000016E36003000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.5, number_type = 0x06, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ // median = 4.5, MAD = 0.5, max_dev = 0.75 => [3.75, 5.25] - {Reveal: `{"result": {"text": 2, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": 4, "number": 10}}`}, - {Reveal: `{"result": {"text": 4, "number": 101}}`}, - {Reveal: `{"result": {"text": 4, "number": 0}}`}, - {Reveal: `{"result": {"text": 5, "number": 0}}`}, - {Reveal: `{"result": {"text": 5, "number": 0}}`}, - {Reveal: `{"result": {"text": 7, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": 9, "number": 0}}`}, // outlier + {Reveal: []byte(`{"result": {"text": 2, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": 4, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": 4, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": 4, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 5, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 5, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 7, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": 9, "number": 0}}`)}, // outlier }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*8, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*8, wantErr: types.ErrNoConsensus, }, { @@ -723,16 +725,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x06, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ // median = -28679, MAD = 404.5 => [-29083.5, -28274.5] - {Reveal: `{"result": {"text": -28930, "number": 0}}`}, - {Reveal: `{"result": {"text": -28000, "number": 10}}`}, // outlier - {Reveal: `{"result": {"text": -30005, "number": 101}}`}, // outlier - {Reveal: `{"result": {"text": -28600, "number": 0}}`}, - {Reveal: `{"result": {"text": -28758, "number": 0}}`}, - {Reveal: `{"result": {"text": -28121, "number": 0}}`}, // outlier + {Reveal: []byte(`{"result": {"text": -28930, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28000, "number": 10}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -30005, "number": 101}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -28600, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28758, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28121, "number": 0}}`)}, // outlier }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: types.ErrNoConsensus, }, { @@ -740,16 +742,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x06, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": -28930, "number": 0}}`}, - {Reveal: `{"result": {"text": -28000, "number": 10}}`}, - {Reveal: `{"result": {"text": -29005, "number": 101}}`}, - {Reveal: `{"result": {"text": -28600, "number": 0}}`}, - {Reveal: `{"result": {"text": -27758, "number": 0}}`}, - {Reveal: `{"result": {"text": -28121, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": -28930, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28000, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": -29005, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": -28600, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -27758, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28121, "number": 0}}`)}, }, consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: types.ErrNoConsensus, }, { @@ -757,16 +759,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F8C7806000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.019, number_type = 0x06, json_path = $.result.text outliers: nil, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": -28930, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": -28000, "number": 10}}`}, - {Reveal: `{"result": {"text": -29005, "number": 101}}`}, // outlier - {Reveal: `{"result": {"text": -28600, "number": 0}}`}, - {Reveal: `{"result": {"text": -27758, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": -28121, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": -28930, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -28000, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": -29005, "number": 101}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -28600, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -27758, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -28121, "number": 0}}`)}, }, // median = -28360.5, MAD = 464, range = [-28833.316, -27887.684] consensus: false, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: types.ErrNoConsensus, }, { @@ -774,16 +776,16 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000013D62006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.3, number_type = 0x06, json_path = $.result.text outliers: []bool{false, false, true, false, false, false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": -28930, "number": 0}}`}, - {Reveal: `{"result": {"text": -28000, "number": 10}}`}, - {Reveal: `{"result": {"text": -29005, "number": 101}}`}, // outlier - {Reveal: `{"result": {"text": -28600, "number": 0}}`}, - {Reveal: `{"result": {"text": -27758, "number": 0}}`}, - {Reveal: `{"result": {"text": -28121, "number": 0}}`}, + {Reveal: []byte(`{"result": {"text": -28930, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28000, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": -29005, "number": 101}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": -28600, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -27758, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": -28121, "number": 0}}`)}, }, // median = -28360.5, MAD = 465, max_dev = 604.5, range = [-28965, -27756] consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*6, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*6, wantErr: nil, }, { @@ -791,18 +793,18 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x06, json_path = $.result.text outliers: []bool{true, false, false, false, false, false, false, true}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 3000000000000000000000000000000000000000, "number": 0}}`}, // outlier - {Reveal: `{"result": {"text": 4000000000000000000000000000000000000000, "number": 10}}`}, - {Reveal: `{"result": {"text": 4000000000000000000000000000000000000000, "number": 101}}`}, - {Reveal: `{"result": {"text": 4000000000000000000000000000000000000000, "number": 0}}`}, - {Reveal: `{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`}, - {Reveal: `{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`}, - {Reveal: `{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`}, - {Reveal: `{"result": {"text": 6000000000000000000000000000000000000000, "number": 0}}`}, // outlier + {Reveal: []byte(`{"result": {"text": 3000000000000000000000000000000000000000, "number": 0}}`)}, // outlier + {Reveal: []byte(`{"result": {"text": 4000000000000000000000000000000000000000, "number": 10}}`)}, + {Reveal: []byte(`{"result": {"text": 4000000000000000000000000000000000000000, "number": 101}}`)}, + {Reveal: []byte(`{"result": {"text": 4000000000000000000000000000000000000000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 5000000000000000000000000000000000000000, "number": 0}}`)}, + {Reveal: []byte(`{"result": {"text": 6000000000000000000000000000000000000000, "number": 0}}`)}, // outlier }, // median = 4.5, MAD = 0.5, range = [4, 5] consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*8, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*8, wantErr: nil, }, { @@ -810,19 +812,19 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424006000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x06, json_path = $.result.text outliers: []bool{true, false, false, false, false, true, false, false, false}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819969, "number": 0}}`}, // too small - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 10}}`}, // ok (min of int256) - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 101}}`}, // ok - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`}, // ok - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`}, // ok - {Reveal: `{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639936, "number": 0}}`}, // too large (max of uint256 + 1) - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`}, // ok - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`}, // ok - {Reveal: `{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`}, // ok + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819969, "number": 0}}`)}, // too small + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 10}}`)}, // ok (min of int256) + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 101}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`)}, // ok + {Reveal: []byte(`{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639936, "number": 0}}`)}, // too large (max of uint256 + 1) + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -57896044618658097711785492504343953926634992332820282019728792003956564819968, "number": 0}}`)}, // ok }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*9, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*9, wantErr: nil, }, { @@ -830,14 +832,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "0200000000000F424007000000000000000D242E726573756C742E74657874", // sigma_multiplier = 1.0, number_type = 0x07, json_path = $.result.text outliers: []bool{false, false, false, true}, reveals: []types.RevealBody{ - {Reveal: `{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`}, // ok (max of uint256) - {Reveal: `{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`}, // ok - {Reveal: `{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`}, // ok - {Reveal: `{"result": {"text": -100, "number": 0}}`}, // negative + {Reveal: []byte(`{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`)}, // ok (max of uint256) + {Reveal: []byte(`{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`)}, // ok + {Reveal: []byte(`{"result": {"text": 115792089237316195423570985008687907853269984665640564039457584007913129639935}}`)}, // ok + {Reveal: []byte(`{"result": {"text": -100, "number": 0}}`)}, // negative }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: nil, }, { @@ -845,14 +847,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "02000000000016E36000000000000000000124", // sigma_multiplier = 1.5, number_type = 0x00, json_path = $ outliers: []bool{false, false, true, false}, reveals: []types.RevealBody{ - {Reveal: `3136`}, - {Reveal: `3136`}, - {Reveal: `"3136"`}, // string, not number - {Reveal: `3136`}, + {Reveal: []byte(`3136`)}, + {Reveal: []byte(`3136`)}, + {Reveal: []byte(`"3136"`)}, // string, not number + {Reveal: []byte(`3136`)}, }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*4, wantErr: nil, }, { @@ -860,14 +862,14 @@ func TestFilter(t *testing.T) { tallyInputAsHex: "01000000000000000124", // json_path = $ outliers: []bool{false, false, false, true}, reveals: []types.RevealBody{ - {Reveal: `"yes"`}, - {Reveal: `"yes"`}, - {Reveal: `"yes"`}, - {Reveal: `yes`}, // invalid due to no surrounding double quotes + {Reveal: []byte(`"yes"`)}, + {Reveal: []byte(`"yes"`)}, + {Reveal: []byte(`"yes"`)}, + {Reveal: []byte(`yes`)}, // invalid due to no surrounding double quotes }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*4, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*4, wantErr: nil, }, } @@ -877,7 +879,7 @@ func TestFilter(t *testing.T) { require.NoError(t, err) for i := 0; i < len(tt.reveals); i++ { - tt.reveals[i].Reveal = base64.StdEncoding.EncodeToString([]byte(tt.reveals[i].Reveal)) + tt.reveals[i].Reveal = tt.reveals[i].Reveal } reveals := make([]types.Reveal, len(tt.reveals)) @@ -891,10 +893,11 @@ func TestFilter(t *testing.T) { gasMeter := types.NewGasMeter(1e13, 0, types.DefaultMaxTallyGasLimit, math.NewIntWithDecimal(1, 18), types.DefaultGasCostBase) - result, err := types.ExecuteFilter( + result, err := keeper.ExecuteFilter( reveals, - base64.StdEncoding.EncodeToString(filterInput), uint16(len(tt.reveals)), - types.DefaultParams(), + filterInput, + uint16(len(tt.reveals)), + tallyConfig, gasMeter, ) require.ErrorIs(t, err, tt.wantErr) @@ -919,9 +922,11 @@ func TestFilterWildcard(t *testing.T) { f := initFixture(t) defaultParams := types.DefaultParams() - err := f.tallyKeeper.SetParams(f.Context(), defaultParams) + err := f.keeper.SetParams(f.Context(), defaultParams) require.NoError(t, err) + tallyConfig := defaultParams.TallyConfig + tests := []struct { name string filterInputHex string // filter input without JSON path as hex @@ -949,7 +954,7 @@ func TestFilterWildcard(t *testing.T) { }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: nil, }, { @@ -968,7 +973,7 @@ func TestFilterWildcard(t *testing.T) { }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: nil, }, { @@ -987,7 +992,7 @@ func TestFilterWildcard(t *testing.T) { }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMode*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMode*7, wantErr: nil, }, { @@ -1006,7 +1011,7 @@ func TestFilterWildcard(t *testing.T) { }, consensus: true, consPubKeys: nil, - tallyGasUsed: defaultParams.GasCostBase + defaultParams.FilterGasCostMultiplierMAD*7, + tallyGasUsed: tallyConfig.GasCostBase + tallyConfig.FilterGasCostMultiplierMAD*7, wantErr: nil, }, } @@ -1018,7 +1023,7 @@ func TestFilterWildcard(t *testing.T) { filterInput = append(filterInput, []byte(tt.jsonPath)...) for i := 0; i < len(tt.reveals); i++ { - tt.reveals[i].Reveal = base64.StdEncoding.EncodeToString([]byte(tt.reveals[i].Reveal)) + tt.reveals[i].Reveal = tt.reveals[i].Reveal } reveals := make([]types.Reveal, len(tt.reveals)) @@ -1032,10 +1037,11 @@ func TestFilterWildcard(t *testing.T) { gasMeter := types.NewGasMeter(1e13, 0, types.DefaultMaxTallyGasLimit, math.NewIntWithDecimal(1, 18), types.DefaultGasCostBase) - result, err := types.ExecuteFilter( + result, err := keeper.ExecuteFilter( reveals, - base64.StdEncoding.EncodeToString(filterInput), uint16(len(tt.reveals)), - types.DefaultParams(), + filterInput, + uint16(len(tt.reveals)), + tallyConfig, gasMeter, ) require.ErrorIs(t, err, tt.wantErr) @@ -1054,7 +1060,7 @@ func TestFilterWildcard(t *testing.T) { } } -var sampleReveal = `{ +var sampleReveal = []byte(`{ "store": { "book": [ { @@ -1077,9 +1083,9 @@ var sampleReveal = `{ } ] } -}` +}`) -var sampleReveal2 = `{ +var sampleReveal2 = []byte(`{ "store": { "book": [ { @@ -1102,9 +1108,9 @@ var sampleReveal2 = `{ } ] } -}` +}`) -var sampleRevealNested = `{ +var sampleRevealNested = []byte(`{ "store": { "books": [ { @@ -1158,9 +1164,9 @@ var sampleRevealNested = `{ } ] } -}` +}`) -var sampleRevealNested2 = `{ +var sampleRevealNested2 = []byte(`{ "store": { "music": [ { @@ -1214,4 +1220,4 @@ var sampleRevealNested2 = `{ } ] } -}` +}`) diff --git a/x/tally/keeper/gas_meter.go b/x/core/keeper/gas_meter.go similarity index 58% rename from x/tally/keeper/gas_meter.go rename to x/core/keeper/gas_meter.go index 38ada84d..08929967 100644 --- a/x/tally/keeper/gas_meter.go +++ b/x/core/keeper/gas_meter.go @@ -11,27 +11,26 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) -// DistributionsFromGasMeter constructs a list of distribution messages to be -// sent to the core contract based on the given gas meter. It takes the ID and -// the height of the request for event emission. -func (k Keeper) DistributionsFromGasMeter(ctx sdk.Context, reqID string, reqHeight uint64, gasMeter *types.GasMeter, burnRatio math.LegacyDec) []types.Distribution { - dists := []types.Distribution{} +func (k Keeper) GetGasMeterResults(ctx sdk.Context, gasMeter *types.GasMeter, drID string, drHeight int64, burnRatio math.LegacyDec) []types.Distribution { attrs := []sdk.Attribute{ - sdk.NewAttribute(types.AttributeDataRequestID, reqID), - sdk.NewAttribute(types.AttributeDataRequestHeight, strconv.FormatUint(reqHeight, 10)), + sdk.NewAttribute(types.AttributeDataRequestID, drID), + sdk.NewAttribute(types.AttributeDataRequestHeight, strconv.FormatInt(drHeight, 10)), sdk.NewAttribute(types.AttributeReducedPayout, strconv.FormatBool(gasMeter.ReducedPayout)), } + // Construct distribution messages to be processed at the end of the function. + dists := []types.Distribution{} + // First distribution message is the combined burn. burn := types.NewBurn(math.NewIntFromUint64(gasMeter.TallyGasUsed()), gasMeter.GasPrice()) dists = append(dists, burn) attrs = append(attrs, sdk.NewAttribute(types.AttributeTallyGas, strconv.FormatUint(gasMeter.TallyGasUsed(), 10))) // Append distribution messages for data proxies. - for _, proxy := range gasMeter.GetProxyGasUsed(reqID, ctx.BlockHeight()) { + for _, proxy := range gasMeter.GetProxyGasUsed(drID, ctx.BlockHeight()) { proxyDist := types.NewDataProxyReward(proxy.PublicKey, proxy.PayoutAddress, proxy.Amount, gasMeter.GasPrice()) dists = append(dists, proxyDist) attrs = append(attrs, sdk.NewAttribute(types.AttributeDataProxyGas, @@ -63,9 +62,87 @@ func (k Keeper) DistributionsFromGasMeter(ctx sdk.Context, reqID string, reqHeig return dists } +func (k Keeper) ProcessDistributions(ctx sdk.Context, tr *TallyResult, minimumStake math.Int, burnRatio math.LegacyDec) error { + dists := k.GetGasMeterResults(ctx, tr.GasMeter, tr.ID, int64(tr.Height), burnRatio) + + // Distribute in order. + denom, err := k.stakingKeeper.BondDenom(ctx) + if err != nil { + return err + } + + // TODO Events + remainingEscrow := tr.GasMeter.GetEscrow() + for _, dist := range dists { + if !remainingEscrow.IsPositive() { + break + } + amount := math.ZeroInt() + + switch { + case dist.Burn != nil: + amount = math.MinInt(dist.Burn.Amount, remainingEscrow) + err = k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(denom, amount))) + if err != nil { + return err + } + + case dist.DataProxyReward != nil: + amount = math.MinInt(dist.DataProxyReward.Amount, remainingEscrow) + payoutAddr, err := sdk.AccAddressFromBech32(dist.DataProxyReward.PayoutAddress) + if err != nil { + // Should not be reachable because the address has been validated. + return err + } + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, payoutAddr, sdk.NewCoins(sdk.NewCoin(denom, amount))) + if err != nil { + return err + } + + case dist.ExecutorReward != nil: + amount = math.MinInt(dist.ExecutorReward.Amount, remainingEscrow) + staker, err := k.GetStaker(ctx, dist.ExecutorReward.Identity) + if err != nil { + return err + } + + // Top up staked amount to minimum stake. + topup := math.ZeroInt() + if staker.Staked.LT(minimumStake) { + topup = math.MinInt(minimumStake.Sub(staker.Staked), amount) + staker.Staked = staker.Staked.Add(topup) + remainingEscrow = remainingEscrow.Sub(topup) + } + staker.PendingWithdrawal = staker.PendingWithdrawal.Add(amount.Sub(topup)) + + err = k.SetStaker(ctx, staker) + if err != nil { + return err + } + } + + remainingEscrow = remainingEscrow.Sub(amount) + } + + // Refund the poster. + if remainingEscrow.IsPositive() { + poster, err := sdk.AccAddressFromBech32(tr.GasMeter.GetPoster()) + if err != nil { + // Should not be reachable because the address has been validated. + return err + } + err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, poster, sdk.NewCoins(sdk.NewCoin(denom, remainingEscrow))) + if err != nil { + return err + } + } + + return nil +} + // MeterProxyGas computes and records the gas consumption of data proxies given // proxy public keys in basic consensus and the request's replication factor. -func (k Keeper) MeterProxyGas(ctx sdk.Context, proxyPubKeys []string, replicationFactor uint16, gasMeter *types.GasMeter) { +func (k Keeper) MeterProxyGas(ctx sdk.Context, proxyPubKeys []string, replicationFactor uint64, gasMeter *types.GasMeter) { if len(proxyPubKeys) == 0 || gasMeter.RemainingExecGas() == 0 { return } @@ -88,9 +165,9 @@ func (k Keeper) MeterProxyGas(ctx sdk.Context, proxyPubKeys []string, replicatio gasUsedPerExecInt := proxyConfig.Fee.Amount.Quo(gasMeter.GasPrice()) var gasUsedPerExec uint64 if gasUsedPerExecInt.IsUint64() { - gasUsedPerExec = min(gasUsedPerExecInt.Uint64(), gasMeter.RemainingExecGas()/uint64(replicationFactor)) + gasUsedPerExec = min(gasUsedPerExecInt.Uint64(), gasMeter.RemainingExecGas()/replicationFactor) } else { - gasUsedPerExec = min(stdmath.MaxUint64, gasMeter.RemainingExecGas()/uint64(replicationFactor)) + gasUsedPerExec = min(stdmath.MaxUint64, gasMeter.RemainingExecGas()/replicationFactor) } gasMeter.ConsumeExecGasForProxy(pubKey, proxyConfig.PayoutAddress, gasUsedPerExec, replicationFactor) @@ -100,7 +177,7 @@ func (k Keeper) MeterProxyGas(ctx sdk.Context, proxyPubKeys []string, replicatio // MeterExecutorGasFallback computes and records the gas consumption of committers // of a data request when basic consensus has not been reached. If checkReveal is // set to true, it will only consume gas for committers that have also revealed. -func MeterExecutorGasFallback(req types.Request, gasCostFallback uint64, gasMeter *types.GasMeter) { +func MeterExecutorGasFallback(req types.DataRequest, gasCostFallback uint64, gasMeter *types.GasMeter) { if len(req.Commits) == 0 || gasMeter.RemainingExecGas() == 0 { return } diff --git a/x/tally/keeper/gas_meter_test.go b/x/core/keeper/gas_meter_test.go similarity index 82% rename from x/tally/keeper/gas_meter_test.go rename to x/core/keeper/gas_meter_test.go index 2acad018..2849a01a 100644 --- a/x/tally/keeper/gas_meter_test.go +++ b/x/core/keeper/gas_meter_test.go @@ -1,5 +1,6 @@ package keeper_test +/* Turned off until x/core endblock implementation is complete import ( "encoding/base64" "encoding/hex" @@ -14,7 +15,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sedaprotocol/seda-chain/testutil/testwasms" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/keeper" + "github.com/sedaprotocol/seda-chain/x/core/types" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" ) @@ -23,7 +25,7 @@ func FuzzGasMetering(f *testing.F) { // Prepare fixed parameters of the fuzz test. defaultParams := types.DefaultParams() - err := fixture.tallyKeeper.SetParams(fixture.Context(), defaultParams) + err := fixture.keeper.SetParams(fixture.Context(), defaultParams) require.NoError(f, err) tallyProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm2(), fixture.Context().BlockTime()) @@ -55,16 +57,28 @@ func FuzzGasMetering(f *testing.F) { t.Log(g0, g1, g2, g3, g4, g5, g6, g7, g8, g9) reveals := map[string]types.RevealBody{ - "a": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g0, ProxyPubKeys: proxyPubKeys}, - "b": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g1, ProxyPubKeys: proxyPubKeys}, - "c": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g2, ProxyPubKeys: proxyPubKeys}, - "d": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g3, ProxyPubKeys: proxyPubKeys}, - "e": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g4, ProxyPubKeys: proxyPubKeys}, - "f": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g5, ProxyPubKeys: proxyPubKeys}, - "g": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g6, ProxyPubKeys: proxyPubKeys}, - "h": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g7, ProxyPubKeys: proxyPubKeys}, - "i": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g8, ProxyPubKeys: proxyPubKeys}, - "j": {ExitCode: 0, Reveal: `{"result": {"text": "A"}}`, GasUsed: g9, ProxyPubKeys: proxyPubKeys}, + "a": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g0, ProxyPubKeys: proxyPubKeys}, + "b": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g1, ProxyPubKeys: proxyPubKeys}, + "c": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g2, ProxyPubKeys: proxyPubKeys}, + "d": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g3, ProxyPubKeys: proxyPubKeys}, + "e": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g4, ProxyPubKeys: proxyPubKeys}, + "f": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g5, ProxyPubKeys: proxyPubKeys}, + "g": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g6, ProxyPubKeys: proxyPubKeys}, + "h": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g7, ProxyPubKeys: proxyPubKeys}, + "i": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g8, ProxyPubKeys: proxyPubKeys}, + "j": {ExitCode: 0, Reveal: []byte(`{"result": {"text": "A"}}`), GasUsed: g9, ProxyPubKeys: proxyPubKeys}, + } + revealsMap := map[string]bool{ + "a": true, + "b": true, + "c": true, + "d": true, + "e": true, + "f": true, + "g": true, + "h": true, + "i": true, + "j": true, } // To avoid commit timeout (no other effect intended) @@ -73,9 +87,9 @@ func FuzzGasMetering(f *testing.F) { commits[fmt.Sprintf("executor-%d", i)] = []byte{} } - tallyRes, dataRes, processedReqs, err := fixture.tallyKeeper.ProcessTallies( + tallyRes, dataRes, processedReqs, err := fixture.keeper.ProcessTallies( fixture.Context(), - []types.Request{{ + []types.DataRequest{{ Commits: commits, Reveals: reveals, ReplicationFactor: uint16(len(reveals)), @@ -85,7 +99,7 @@ func FuzzGasMetering(f *testing.F) { TallyGasLimit: tallyGasLimit, TallyProgramID: hex.EncodeToString(tallyProgram.Hash), }}, - types.DefaultParams(), false, + types.DefaultParams().TallyConfig, false, ) require.NoError(t, err) @@ -117,7 +131,7 @@ func FuzzGasMetering(f *testing.F) { tallySum = tallySum.Add(math.NewIntFromUint64(gasMeter.RemainingTallyGas())) require.Equal(t, tallySum.String(), strconv.FormatUint(tallyGasLimit, 10)) - dists := fixture.tallyKeeper.DistributionsFromGasMeter(fixture.Context(), "1", 1, gasMeter, types.DefaultBurnRatio) + dists := fixture.keeper.GetGasMeterResults(fixture.Context(), gasMeter, "drID", 1, types.DefaultBurnRatio) require.Len(t, dists, 13) totalDist := math.NewInt(0) @@ -142,7 +156,7 @@ func FuzzGasMetering(f *testing.F) { require.True(t, totalGasPayed.LTE(sumExec.Add((tallySum))), "total gas paid is not less than or equal to the sum of exec and tally gas used") gasMeter.SetReducedPayoutMode() - distsReduced := fixture.tallyKeeper.DistributionsFromGasMeter(fixture.Context(), "1", 1, gasMeter, types.DefaultBurnRatio) + distsReduced := fixture.keeper.GetGasMeterResults(fixture.Context(), gasMeter, "drID", 1, types.DefaultBurnRatio) totalDistReduced := math.NewInt(0) burnReduced := math.NewInt(0) for _, dist := range distsReduced { @@ -183,15 +197,15 @@ func TestReducedPayoutWithProxies(t *testing.T) { // Scenario: 4 data proxy calls (3 to the same proxy, 1 to a different proxy), replication factor = 1. gasMeter := types.NewGasMeter(150000000000000, 300000000000000, types.DefaultMaxTallyGasLimit, math.NewInt(100000), types.DefaultGasCostBase) - fixture.tallyKeeper.MeterProxyGas(fixture.Context(), []string{"020173bd90e73c5f8576b3141c53aa9959b10a1daf1bc9c0ccf0a942932c703dec", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"}, 1, gasMeter) + fixture.keeper.MeterProxyGas(fixture.Context(), []string{"020173bd90e73c5f8576b3141c53aa9959b10a1daf1bc9c0ccf0a942932c703dec", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0", "03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"}, 1, gasMeter) - tallyRes := types.TallyResult{ + tallyRes := keeper.TallyResult{ Reveals: []types.Reveal{ {Executor: "020c4fe9e5063e7b5051284423089682082cf085a3b8f9e86bdb30407d761efc49"}, }, GasMeter: gasMeter, GasReports: []uint64{81644889168750}, - FilterResult: types.FilterResult{ + FilterResult: keeper.FilterResult{ ProxyPubKeys: []string{proxyPubKey1, proxyPubKey2}, Outliers: []bool{false}, }, @@ -202,7 +216,7 @@ func TestReducedPayoutWithProxies(t *testing.T) { require.Equalf(t, uint64(81644889168750), gasMeter.ExecutionGasUsed(), "expected exec gas used %d, got %d", 81644889168750, gasMeter.ExecutionGasUsed()) require.Equalf(t, uint64(1000000000000), gasMeter.TallyGasUsed(), "expected tally gas used %d, got %d", 1000000100000, gasMeter.TallyGasUsed()) - dists := fixture.tallyKeeper.DistributionsFromGasMeter(fixture.Context(), "1", 1, gasMeter, types.DefaultBurnRatio) + dists := fixture.keeper.GetGasMeterResults(fixture.Context(), gasMeter, "drID", 1, types.DefaultBurnRatio) require.Len(t, dists, 6) @@ -232,7 +246,7 @@ func TestReducedPayoutWithProxies(t *testing.T) { require.Equalf(t, uint64(81644889168750), gasMeter.ExecutionGasUsed(), "expected exec gas used %d, got %d", 81644889168750, gasMeter.ExecutionGasUsed()) require.Equalf(t, uint64(1000000000000), gasMeter.TallyGasUsed(), "expected tally gas used %d, got %d", 1000000100000, gasMeter.TallyGasUsed()) - distsReduced := fixture.tallyKeeper.DistributionsFromGasMeter(fixture.Context(), "1", 1, gasMeter, types.DefaultBurnRatio) + distsReduced := fixture.keeper.GetGasMeterResults(fixture.Context(), gasMeter, "drID", 1, types.DefaultBurnRatio) require.Equal(t, "1132895783375000000", distsReduced[0].Burn.Amount.String(), "Burn amount is incorrect") @@ -257,3 +271,4 @@ func TestReducedPayoutWithProxies(t *testing.T) { // Sanity check that the difference between the two distributions is the same as the reduced payout. require.Equal(t, distsReduced[0].Burn.Amount.Sub(dists[0].Burn.Amount).String(), dists[5].ExecutorReward.Amount.Sub(distsReduced[5].ExecutorReward.Amount).String(), "Difference between burn and executor reward is not the same as the reduced payout") } +*/ diff --git a/x/tally/keeper/genesis.go b/x/core/keeper/genesis.go similarity index 78% rename from x/tally/keeper/genesis.go rename to x/core/keeper/genesis.go index 93888b4e..ba784244 100644 --- a/x/tally/keeper/genesis.go +++ b/x/core/keeper/genesis.go @@ -3,12 +3,12 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) // InitGenesis initializes the store based on the given genesis state. func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) { - err := k.params.Set(ctx, data.Params) + err := k.SetParams(ctx, data.Params) if err != nil { panic(err) } @@ -19,7 +19,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) types.GenesisState { var gs types.GenesisState var err error - gs.Params, err = k.params.Get(ctx) + gs.Params, err = k.GetParams(ctx) if err != nil { panic(err) } diff --git a/x/core/keeper/genesis_test.go b/x/core/keeper/genesis_test.go new file mode 100644 index 00000000..9315c781 --- /dev/null +++ b/x/core/keeper/genesis_test.go @@ -0,0 +1,35 @@ +package keeper_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func TestExportGenesis(t *testing.T) { + f := initFixture(t) + + // TODO Test rest of the params + gs := types.DefaultGenesisState() + gs.Params.TallyConfig.FilterGasCostNone = 200_000 + gs.Params.TallyConfig.FilterGasCostMultiplierMode = 400_000 + gs.Params.TallyConfig.FilterGasCostMultiplierMAD = 600_000 + f.keeper.SetParams(f.Context(), gs.Params) + + err := types.ValidateGenesis(*gs) + require.NoError(t, err) + + // Export and import genesis. + exportGenesis := f.keeper.ExportGenesis(f.Context()) + + err = types.ValidateGenesis(exportGenesis) + require.NoError(t, err) + + f.keeper.InitGenesis(f.Context(), exportGenesis) + + afterParams, err := f.keeper.GetParams(f.Context()) + require.NoError(t, err) + require.Equal(t, gs.Params, afterParams) +} diff --git a/x/tally/keeper/grpc_query.go b/x/core/keeper/grpc_query.go similarity index 89% rename from x/tally/keeper/grpc_query.go rename to x/core/keeper/grpc_query.go index 1b74929f..d4c18c5f 100644 --- a/x/tally/keeper/grpc_query.go +++ b/x/core/keeper/grpc_query.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) var _ types.QueryServer = Querier{} diff --git a/x/tally/keeper/integration_helpers_test.go b/x/core/keeper/integration_helpers_test.go similarity index 56% rename from x/tally/keeper/integration_helpers_test.go rename to x/core/keeper/integration_helpers_test.go index 0b8b5e3e..b9090d92 100644 --- a/x/tally/keeper/integration_helpers_test.go +++ b/x/core/keeper/integration_helpers_test.go @@ -9,26 +9,24 @@ import ( "strings" "testing" + vrf "github.com/sedaprotocol/vrf-go" "github.com/stretchr/testify/require" "golang.org/x/crypto/sha3" "golang.org/x/exp/rand" "github.com/cometbft/cometbft/crypto/secp256k1" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - "cosmossdk.io/math" - + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "github.com/cosmos/cosmos-sdk/client/tx" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - vrf "github.com/sedaprotocol/vrf-go" - "github.com/sedaprotocol/seda-chain/testutil" "github.com/sedaprotocol/seda-chain/testutil/testwasms" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" + "github.com/sedaprotocol/seda-chain/x/wasm" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" ) @@ -37,50 +35,26 @@ const ( defaultRevealTimeoutBlocks = 5 ) -type PostDataRequestResponse struct { - DrID string `json:"dr_id"` - Height uint64 `json:"height"` -} - type commitRevealConfig struct { requestHeight uint64 requestMemo string - reveal string + reveal string // base64 string (TODO: change to []byte) proxyPubKeys []string gasUsed uint64 exitCode byte } -func (f *fixture) uploadOraclePrograms(t testing.TB) { - for _, op := range testwasms.TestWasms { - execProgram := wasmstoragetypes.NewOracleProgram(op, f.Context().BlockTime()) - err := f.wasmStorageKeeper.OracleProgram.Set(f.Context(), execProgram.Hash, execProgram) - require.NoError(t, err) - } -} +// commitRevealDataRequest simulates stakers committing and revealing +// for a data request. It returns the data request ID. +func (f *fixture) commitRevealDataRequest(t testing.TB, stakers []staker, replicationFactor, numCommits, numReveals int, timeout bool, config commitRevealConfig) (string, []staker) { + // Upload data request and tally oracle programs. + execProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm(), f.Context().BlockTime()) + err := f.wasmStorageKeeper.OracleProgram.Set(f.Context(), execProgram.Hash, execProgram) + require.NoError(t, err) -// executeDataRequestFlow posts a data request using the deployer account and -// executes given numbers of commits and reveals for the request using the -// stakers accounts. It returns the data request ID. -func (f *fixture) executeDataRequestFlow( - t testing.TB, - execProgramBytes, tallyProgramBytes []byte, - replicationFactor, numCommits, numReveals int, timeout bool, - config commitRevealConfig, -) string { - var execProgram, tallyProgram wasmstoragetypes.OracleProgram - if execProgramBytes != nil { - execProgram = wasmstoragetypes.NewOracleProgram(execProgramBytes, f.Context().BlockTime()) - } else { - randIndex := rand.Intn(len(testwasms.TestWasms)) - execProgram = wasmstoragetypes.NewOracleProgram(testwasms.TestWasms[randIndex], f.Context().BlockTime()) - } - if tallyProgramBytes != nil { - tallyProgram = wasmstoragetypes.NewOracleProgram(tallyProgramBytes, f.Context().BlockTime()) - } else { - randIndex := rand.Intn(len(testwasms.TestWasms)) - tallyProgram = wasmstoragetypes.NewOracleProgram(testwasms.TestWasms[randIndex], f.Context().BlockTime()) - } + tallyProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm2(), f.Context().BlockTime()) + err = f.wasmStorageKeeper.OracleProgram.Set(f.Context(), tallyProgram.Hash, tallyProgram) + require.NoError(t, err) // Post a data request. res, err := f.postDataRequest(execProgram.Hash, tallyProgram.Hash, config.requestMemo, replicationFactor) @@ -89,10 +63,10 @@ func (f *fixture) executeDataRequestFlow( drID := res.DrID // The stakers commit and reveal. - revealMsgs, err := f.commitDataRequest(f.stakers[:numCommits], res.Height, drID, config) + revealMsgs, err := f.commitDataRequest(t, stakers[:numCommits], int64(res.Height), drID, config) require.NoError(t, err) - err = f.executeReveals(f.stakers, revealMsgs[:numReveals]) + err = f.executeReveals(stakers, revealMsgs[:numReveals]) require.NoError(t, err) if timeout { @@ -105,77 +79,91 @@ func (f *fixture) executeDataRequestFlow( f.AddBlock() } } - return res.DrID + return res.DrID, stakers } -// executeDataRequestFlowWithTallyTestItem posts a data request using the deployer -// account and executes a commit and reveal for the request using a staker account. -// It then returns the data request ID and the randomly selected TallyTestItem, -// which contains the expected tally execution results. -func (f *fixture) executeDataRequestFlowWithTallyTestItem(t testing.TB, entropy []byte) (string, testwasms.TallyTestItem) { - randIndex := rand.Intn(len(testwasms.TestWasms)) - execProgram := wasmstoragetypes.NewOracleProgram(testwasms.TestWasms[randIndex], f.Context().BlockTime()) - - randIndex = rand.Intn(len(testwasms.TallyTestItems)) - testItem := testwasms.TallyTestItems[randIndex] - tallyProgram := wasmstoragetypes.NewOracleProgram(testItem.TallyProgram, f.Context().BlockTime()) - - config := commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString(entropy), - reveal: testItem.Reveal, - proxyPubKeys: []string{}, - gasUsed: testItem.GasUsed, - } +func (f *fixture) commitRevealDataRequests(t testing.TB, stakers []staker, replicationFactor, numCommits, numReveals int, timeout bool, config commitRevealConfig) { + // Upload data request and tally oracle programs. + execProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm(), f.Context().BlockTime()) + err := f.wasmStorageKeeper.OracleProgram.Set(f.Context(), execProgram.Hash, execProgram) + require.NoError(t, err) - // Post a data request. - res, err := f.postDataRequest(execProgram.Hash, tallyProgram.Hash, config.requestMemo, 1) + tallyProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm2(), f.Context().BlockTime()) + err = f.wasmStorageKeeper.OracleProgram.Set(f.Context(), tallyProgram.Hash, tallyProgram) require.NoError(t, err) - drID := res.DrID + for i := 0; i < 25; i++ { + // Post a data request. + res, err := f.postDataRequest( + execProgram.Hash, + tallyProgram.Hash, + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), + replicationFactor, + ) + require.NoError(t, err) - // The stakers commit and reveal. - revealMsgs, err := f.commitDataRequest(f.stakers[:1], res.Height, drID, config) - require.NoError(t, err) + drID := res.DrID - err = f.executeReveals(f.stakers, revealMsgs[:1]) - require.NoError(t, err) + // The stakers commit and reveal. + revealMsgs, err := f.commitDataRequest(t, stakers[:numCommits], int64(res.Height), drID, config) + require.NoError(t, err) + + err = f.executeReveals(stakers, revealMsgs[:numReveals]) + require.NoError(t, err) - return res.DrID, testItem + if timeout { + timeoutBlocks := defaultCommitTimeoutBlocks + if numCommits == replicationFactor { + timeoutBlocks = defaultRevealTimeoutBlocks + } + + for range timeoutBlocks { + f.AddBlock() + } + } + } } -func (f *fixture) postDataRequest(execProgHash, tallyProgHash []byte, requestMemo string, replicationFactor int) (PostDataRequestResponse, error) { +func (f *fixture) postDataRequest(execProgHash, tallyProgHash []byte, requestMemo string, replicationFactor int) (*wasm.PostRequestResponsePayload, error) { amount, ok := math.NewIntFromString("200600000000000000000") if !ok { - return PostDataRequestResponse{}, fmt.Errorf("failed to convert string to int") + return nil, fmt.Errorf("failed to convert string to int") } - resJSON, err := f.contractKeeper.Execute( - f.Context(), - f.coreContractAddr, - f.deployer, + + resBytes, err := f.executeCoreContract( + f.deployer.String(), testutil.PostDataRequestMsg(execProgHash, tallyProgHash, requestMemo, replicationFactor), sdk.NewCoins(sdk.NewCoin(bondDenom, amount)), ) if err != nil { - return PostDataRequestResponse{}, err + return nil, err } - var res PostDataRequestResponse - err = json.Unmarshal(resJSON, &res) + var wasmRes wasmtypes.MsgExecuteContractResponse + if err := wasmRes.Unmarshal(resBytes); err != nil { + return nil, err + } + var postRes wasm.PostRequestResponsePayload + err = json.Unmarshal(wasmRes.Data, &postRes) if err != nil { - return PostDataRequestResponse{}, err + return nil, err } - return res, nil + return &postRes, nil } // commitDataRequest executes a commit for each of the given stakers and // returns a list of corresponding reveal messages. -func (f *fixture) commitDataRequest(stakers []staker, height uint64, drID string, config commitRevealConfig) ([][]byte, error) { +func (f *fixture) commitDataRequest(t testing.TB, stakers []staker, height int64, drID string, config commitRevealConfig) ([][]byte, error) { + revealBytes, err := base64.StdEncoding.DecodeString(config.reveal) + if err != nil { + return nil, err + } + revealBody := types.RevealBody{ - RequestID: drID, - Reveal: config.reveal, + DrId: drID, + Reveal: revealBytes, GasUsed: config.gasUsed, - ExitCode: config.exitCode, + ExitCode: uint32(config.exitCode), ProxyPubKeys: config.proxyPubKeys, } @@ -186,11 +174,11 @@ func (f *fixture) commitDataRequest(stakers []staker, height uint64, drID string return nil, err } - proof, err := f.generateCommitProof(stakers[i].key, drID, commitment, height) + proof, err := f.generateCommitProof(t, stakers[i].key, drID, commitment, height) if err != nil { return nil, err } - commitMsg := testutil.CommitMsg(drID, commitment, stakers[i].pubKey, proof, config.gasUsed) + commitMsg := testutil.CommitMsg(drID, commitment, stakers[i].pubKey, proof) err = f.executeCommitReveal(stakers[i].address, commitMsg, 500000) if err != nil { @@ -232,29 +220,22 @@ func (f *fixture) addStakers(t testing.TB, num int) []staker { address: privKey.PubKey().Address().Bytes(), } - _, err := f.contractKeeper.Execute( - f.Context(), - f.coreContractAddr, - f.deployer, - testutil.AddToAllowListMsg(stakers[i].pubKey), - sdk.NewCoins(), - ) + // Add to allowlist. + _, err := f.executeCoreContract(f.deployer.String(), testutil.AddToAllowListMsg(stakers[i].pubKey), sdk.NewCoins()) require.NoError(t, err) - f.initAccountWithCoins(t, stakers[i].address, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1e18)))) + // Stake. + f.initAccountWithCoins(t, stakers[i].address, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1e19)))) - proof := f.generateStakeProof(t, stakers[i].key) - _, err = f.contractKeeper.Execute( - f.Context(), - f.coreContractAddr, - stakers[i].address, - testutil.StakeMsg(stakers[i].pubKey, proof), - sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), - ) + proof := f.generateStakeProof(t, stakers[i].key, 0) + _, err = f.executeCoreContract(sdk.AccAddress(stakers[i].address).String(), testutil.StakeMsg(stakers[i].pubKey, proof), sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1000000000000000000)))) require.NoError(t, err) - } - f.stakers = stakers + // Another stake to test sequence number. + proof2 := f.generateStakeProof(t, stakers[i].key, 1) + _, err = f.executeCoreContract(sdk.AccAddress(stakers[i].address).String(), testutil.StakeMsg(stakers[i].pubKey, proof2), sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(3)))) + require.NoError(t, err) + } return stakers } @@ -271,69 +252,34 @@ func (f *fixture) pauseContract(t testing.TB) { // generateStakeProof generates a proof for a stake message given a // base64-encoded memo. -func (f *fixture) generateStakeProof(t testing.TB, signKey []byte) string { - // TODO - // var sequence uint64 = 0 - +func (f *fixture) generateStakeProof(t testing.TB, signKey []byte, seqNum uint64) string { memo := "YWRkcmVzcw==" memoBytes, err := base64.StdEncoding.DecodeString(memo) require.NoError(t, err) - // Create slices for each component - stakeBytes := []byte("stake") - - hasher := sha3.NewLegacyKeccak256() - hasher.Write(memoBytes) - memoHash := hasher.Sum(nil) - - chainIDBytes := []byte(f.chainID) - contractAddrBytes := []byte(f.coreContractAddr.String()) - - sequenceBytes := make([]byte, 16) - // binary.BigEndian.PutUint64(sequenceBytes, sequence) // TODO - - allBytes := append([]byte{}, stakeBytes...) - allBytes = append(allBytes, memoHash...) - allBytes = append(allBytes, chainIDBytes...) - allBytes = append(allBytes, contractAddrBytes...) - allBytes = append(allBytes, sequenceBytes...) - - hasher.Reset() - hasher.Write(allBytes) - hash := hasher.Sum(nil) + msg := types.MsgStake{ + Memo: hex.EncodeToString(memoBytes), + } + hash, err := msg.MsgHash(f.coreContractAddr.String(), f.chainID, seqNum) + require.NoError(t, err) proof, err := vrf.NewK256VRF().Prove(signKey, hash) require.NoError(t, err) return hex.EncodeToString(proof) } -func (f *fixture) generateCommitProof(signKey []byte, drID, commitment string, drHeight uint64) (string, error) { - commitBytes := []byte("commit_data_result") - drIDBytes := []byte(drID) - - drHeightBytes := make([]byte, 8) - binary.BigEndian.PutUint64(drHeightBytes, drHeight) - - commitmentBytes := []byte(commitment) - chainIDBytes := []byte(f.chainID) - contractAddrBytes := []byte(f.coreContractAddr.String()) - - allBytes := append([]byte{}, commitBytes...) - allBytes = append(allBytes, drIDBytes...) - allBytes = append(allBytes, drHeightBytes...) - allBytes = append(allBytes, commitmentBytes...) - allBytes = append(allBytes, chainIDBytes...) - allBytes = append(allBytes, contractAddrBytes...) - - hasher := sha3.NewLegacyKeccak256() - hasher.Write(allBytes) - hash := hasher.Sum(nil) +func (f *fixture) generateCommitProof(t testing.TB, signKey []byte, drID, commitment string, drHeight int64) (string, error) { + msg := types.MsgCommit{ + DrId: drID, + Commit: commitment, + } + hash, err := msg.MsgHash(f.coreContractAddr.String(), f.chainID, drHeight) + require.NoError(t, err) proof, err := vrf.NewK256VRF().Prove(signKey, hash) if err != nil { return "", err } - return hex.EncodeToString(proof), nil } @@ -349,26 +295,22 @@ func (f *fixture) initAccountWithCoins(t testing.TB, addr sdk.AccAddress, coins // salt field, the salt must be provided separately. func (f *fixture) generateRevealBodyHash(rb types.RevealBody) ([]byte, error) { revealHasher := sha3.NewLegacyKeccak256() - revealBytes, err := base64.StdEncoding.DecodeString(rb.Reveal) - if err != nil { - return nil, err - } - revealHasher.Write(revealBytes) + revealHasher.Write(rb.Reveal) revealHash := revealHasher.Sum(nil) hasher := sha3.NewLegacyKeccak256() - idBytes, err := hex.DecodeString(rb.RequestID) + idBytes, err := hex.DecodeString(rb.DrId) if err != nil { return nil, err } hasher.Write(idBytes) reqHeightBytes := make([]byte, 8) - binary.BigEndian.PutUint64(reqHeightBytes, rb.RequestBlockHeight) + binary.BigEndian.PutUint64(reqHeightBytes, rb.DrBlockHeight) hasher.Write(reqHeightBytes) - hasher.Write([]byte{rb.ExitCode}) + hasher.Write([]byte{byte(rb.ExitCode)}) gasUsedBytes := make([]byte, 8) binary.BigEndian.PutUint64(gasUsedBytes, rb.GasUsed) @@ -400,13 +342,13 @@ func (f *fixture) createRevealMsg(staker staker, revealBody types.RevealBody) ([ } msg := testutil.RevealMsg( - revealBody.RequestID, - revealBody.Reveal, + revealBody.DrId, + base64.StdEncoding.EncodeToString(revealBody.Reveal), staker.pubKey, proof, revealBody.ProxyPubKeys, - revealBody.ExitCode, - revealBody.RequestBlockHeight, + byte(revealBody.ExitCode), + revealBody.DrBlockHeight, revealBody.GasUsed, ) @@ -428,7 +370,7 @@ func generateRevealProof(signKey []byte, revealBodyHash []byte, chainID, coreCon allBytes := append(revealBytes, revealBodyHash...) allBytes = append(allBytes, []byte(chainID)...) - allBytes = append(allBytes, []byte(coreContractAddr)...) + // allBytes = append(allBytes, []byte(coreContractAddr)...) hasher := sha3.NewLegacyKeccak256() hasher.Write(allBytes) @@ -477,16 +419,30 @@ func (f *fixture) executeCommitReveal(sender sdk.AccAddress, msg []byte, gasLimi } // Execute the message. - _, err = f.contractKeeper.Execute( - f.Context(), - f.coreContractAddr, - sender, - msg, - sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1))), - ) + _, err = f.executeCoreContract(sender.String(), msg, sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewIntFromUint64(1)))) if err != nil { return err } f.SetInfiniteGasMeter() return nil } + +func (f *fixture) executeCoreContract(sender string, msg []byte, funds sdk.Coins) ([]byte, error) { + execMsg := &wasmtypes.MsgExecuteContract{ + Sender: sender, + Contract: f.coreContractAddr.String(), + Msg: msg, + Funds: funds, + } + + handler := f.router.Handler(execMsg) + if handler == nil { + return nil, fmt.Errorf("failed to find handler for message type %T", execMsg) + } + + result, err := handler(f.Context(), execMsg) + if err != nil { + return nil, err + } + return result.Data, nil +} diff --git a/x/tally/keeper/integration_test.go b/x/core/keeper/integration_test.go similarity index 84% rename from x/tally/keeper/integration_test.go rename to x/core/keeper/integration_test.go index d628fc4f..101fc1fe 100644 --- a/x/tally/keeper/integration_test.go +++ b/x/core/keeper/integration_test.go @@ -13,8 +13,8 @@ import ( "github.com/cometbft/cometbft/crypto/ed25519" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/CosmWasm/wasmd/x/wasm" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + sdkwasm "github.com/CosmWasm/wasmd/x/wasm" + sdkwasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "cosmossdk.io/core/appmodule" @@ -55,15 +55,17 @@ import ( "github.com/sedaprotocol/seda-chain/testutil/testwasms" batchingkeeper "github.com/sedaprotocol/seda-chain/x/batching/keeper" batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" + "github.com/sedaprotocol/seda-chain/x/core" + "github.com/sedaprotocol/seda-chain/x/core/keeper" + corekeeper "github.com/sedaprotocol/seda-chain/x/core/keeper" + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" dataproxykeeper "github.com/sedaprotocol/seda-chain/x/data-proxy/keeper" dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" pubkeykeeper "github.com/sedaprotocol/seda-chain/x/pubkey/keeper" pubkeytypes "github.com/sedaprotocol/seda-chain/x/pubkey/types" "github.com/sedaprotocol/seda-chain/x/staking" 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/types" + "github.com/sedaprotocol/seda-chain/x/wasm" wasmstorage "github.com/sedaprotocol/seda-chain/x/wasm-storage" wasmstoragekeeper "github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" @@ -81,19 +83,19 @@ type fixture struct { chainID string coreContractAddr sdk.AccAddress deployer sdk.AccAddress - stakers []staker + keeper *keeper.Keeper accountKeeper authkeeper.AccountKeeper bankKeeper bankkeeper.Keeper stakingKeeper stakingkeeper.Keeper - contractKeeper wasmkeeper.PermissionedKeeper - wasmKeeper wasmkeeper.Keeper + pubKeyKeeper *pubkeykeeper.Keeper + contractKeeper sdkwasmkeeper.PermissionedKeeper + wasmKeeper sdkwasmkeeper.Keeper wasmStorageKeeper wasmstoragekeeper.Keeper - tallyKeeper keeper.Keeper - tallyMsgServer types.MsgServer batchingKeeper batchingkeeper.Keeper dataProxyKeeper *dataproxykeeper.Keeper wasmViewKeeper wasmtypes.ViewKeeper logBuf *bytes.Buffer + router *baseapp.MsgServiceRouter } func initFixture(t testing.TB) *fixture { @@ -106,11 +108,11 @@ func initFixture(t testing.TB) *fixture { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, sdkstakingtypes.StoreKey, wasmstoragetypes.StoreKey, - wasmtypes.StoreKey, pubkeytypes.StoreKey, batchingtypes.StoreKey, types.StoreKey, - dataproxytypes.StoreKey, + wasmtypes.StoreKey, pubkeytypes.StoreKey, batchingtypes.StoreKey, dataproxytypes.StoreKey, + coretypes.StoreKey, ) - mb := module.NewBasicManager(auth.AppModuleBasic{}, bank.AppModuleBasic{}, wasmstorage.AppModuleBasic{}, wasm.AppModuleBasic{}) + mb := module.NewBasicManager(auth.AppModuleBasic{}, bank.AppModuleBasic{}, wasmstorage.AppModuleBasic{}, sdkwasm.AppModuleBasic{}, core.AppModuleBasic{}) interfaceRegistry := sdktestutil.CodecOptions{ AccAddressPrefix: params.Bech32PrefixAccAddr, @@ -146,6 +148,7 @@ func initFixture(t testing.TB) *fixture { sdkstakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, sdkstakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, wasmtypes.ModuleName: {authtypes.Burner}, + coretypes.ModuleName: {authtypes.Burner}, } accountKeeper := authkeeper.NewAccountKeeper( @@ -180,7 +183,7 @@ func initFixture(t testing.TB) *fixture { // x/wasm router := baseapp.NewMsgServiceRouter() - wasmKeeper := wasmkeeper.NewKeeper( + sdkWasmKeeper := sdkwasmkeeper.NewKeeper( cdc, runtime.NewKVStoreService(keys[wasmtypes.StoreKey]), accountKeeper, @@ -192,12 +195,17 @@ func initFixture(t testing.TB) *fixture { wasmtypes.DefaultWasmConfig(), app.GetWasmCapabilities(), authtypes.NewModuleAddress(govtypes.ModuleName).String(), - []wasmkeeper.Option{}..., + []sdkwasmkeeper.Option{}..., ) - require.NoError(t, wasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())) - contractKeeper := wasmkeeper.NewDefaultPermissionKeeper(&wasmKeeper) + wasmKeeper := wasm.NewKeeper( + &sdkWasmKeeper, + stakingKeeper, + cdc, + router, + ) + contractKeeper := sdkwasmkeeper.NewDefaultPermissionKeeper(wasmKeeper) wasmStorageKeeper := wasmstoragekeeper.NewKeeper( cdc, runtime.NewKVStoreService(keys[wasmstoragetypes.StoreKey]), @@ -209,6 +217,10 @@ func initFixture(t testing.TB) *fixture { contractKeeper, ) + wasmKeeper.SetWasmStorageKeeper(wasmStorageKeeper) + + require.NoError(t, wasmKeeper.SetParams(ctx, wasmtypes.DefaultParams())) + slashingKeeper := slashingkeeper.NewKeeper( cdc, nil, @@ -246,42 +258,54 @@ func initFixture(t testing.TB) *fixture { addresscodec.NewBech32Codec(params.Bech32PrefixValAddr), ) - tallyKeeper := keeper.NewKeeper( + deployer := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + coreKeeper := corekeeper.NewKeeper( cdc, - runtime.NewKVStoreService(keys[types.StoreKey]), + runtime.NewKVStoreService(keys[coretypes.StoreKey]), wasmStorageKeeper, batchingKeeper, dataProxyKeeper, + stakingKeeper, + bankKeeper, contractKeeper, wasmKeeper, - authority.String(), + deployer.String(), ) - tallyMsgServer := keeper.NewMsgServerImpl(tallyKeeper) - authModule := auth.NewAppModule(cdc, accountKeeper, app.RandomGenesisAccounts, nil) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper, pubKeyKeeper) wasmStorageModule := wasmstorage.NewAppModule(cdc, *wasmStorageKeeper) - tallyModule := tally.NewAppModule(cdc, tallyKeeper) + wasmModule := wasm.NewAppModule(cdc, wasmKeeper, stakingKeeper, accountKeeper, bankKeeper, router, nil) + coreModule := core.NewAppModule(cdc, coreKeeper) integrationApp := testutil.NewIntegrationApp(ctx, logger, keys, cdc, router, map[string]appmodule.AppModule{ authtypes.ModuleName: authModule, banktypes.ModuleName: bankModule, sdkstakingtypes.ModuleName: stakingModule, wasmstoragetypes.ModuleName: wasmStorageModule, - types.ModuleName: tallyModule, + wasmtypes.ModuleName: wasmModule, + coretypes.ModuleName: coreModule, }) + wasmKeeper.SetRouter(router) // TODO: Check why IntegrationApp setup fails to initialize params. bankKeeper.SetSendEnabled(ctx, "aseda", true) - err = tallyKeeper.SetParams(ctx, types.DefaultParams()) + err = coreKeeper.SetParams(ctx, coretypes.DefaultParams()) require.NoError(t, err) - // Upload, instantiate, and configure the Core Contract. - deployer := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address()) + err = pubKeyKeeper.SetProvingScheme( + ctx, + pubkeytypes.ProvingScheme{ + Index: 0, // SEDA Key Index for Secp256k1 + IsActivated: true, + ActivationHeight: ctx.BlockHeight(), + }, + ) + require.NoError(t, err) + // Upload, instantiate, and configure the Core Contract. int1e21, ok := math.NewIntFromString("10000000000000000000000000") require.True(t, ok) err = bankKeeper.MintCoins(ctx, minttypes.ModuleName, sdk.NewCoins(sdk.NewCoin(bondDenom, int1e21))) @@ -312,39 +336,33 @@ func initFixture(t testing.TB) *fixture { err = wasmStorageKeeper.CoreContractRegistry.Set(ctx, coreContractAddr.String()) require.NoError(t, err) - _, err = contractKeeper.Execute( - ctx, - coreContractAddr, - deployer, - []byte(setStakingConfigMsg), - sdk.NewCoins(), - ) - require.NoError(t, err) - - f := fixture{ + f := &fixture{ IntegationApp: integrationApp, chainID: chainID, deployer: deployer, cdc: cdc, txConfig: txConfig, coreContractAddr: coreContractAddr, + keeper: &coreKeeper, accountKeeper: accountKeeper, bankKeeper: bankKeeper, stakingKeeper: *stakingKeeper, + pubKeyKeeper: pubKeyKeeper, contractKeeper: *contractKeeper, - wasmKeeper: wasmKeeper, + wasmKeeper: *wasmKeeper.Keeper, wasmStorageKeeper: *wasmStorageKeeper, - tallyKeeper: tallyKeeper, - tallyMsgServer: tallyMsgServer, batchingKeeper: batchingKeeper, dataProxyKeeper: dataProxyKeeper, wasmViewKeeper: wasmKeeper, logBuf: buf, + router: router, } + f.SetContextChainID(chainID) + + _, err = f.executeCoreContract(f.deployer.String(), []byte(setStakingConfigMsg), sdk.NewCoins()) + require.NoError(t, err) - f.addStakers(t, 5) - f.uploadOraclePrograms(t) - return &f + return f } func (f *fixture) SetDataProxyConfig(proxyPubKey, payoutAddr string, proxyFee sdk.Coin) error { diff --git a/x/core/keeper/keeper.go b/x/core/keeper/keeper.go new file mode 100644 index 00000000..5d9019bf --- /dev/null +++ b/x/core/keeper/keeper.go @@ -0,0 +1,216 @@ +package keeper + +import ( + "fmt" + "sort" + + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + + "cosmossdk.io/collections" + collcdc "cosmossdk.io/collections/codec" + storetypes "cosmossdk.io/core/store" + "cosmossdk.io/log" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +type Keeper struct { + wasmStorageKeeper types.WasmStorageKeeper + batchingKeeper types.BatchingKeeper + dataProxyKeeper types.DataProxyKeeper + stakingKeeper types.StakingKeeper + bankKeeper types.BankKeeper + wasmKeeper wasmtypes.ContractOpsKeeper + wasmViewKeeper wasmtypes.ViewKeeper + authority string + + Schema collections.Schema + + // Staking-related states: + // allowlist is an owner-controlled allowlist of staker public keys. + allowlist collections.KeySet[string] + // stakers is a map of staker public keys to staker objects. + stakers collections.Map[string, types.Staker] + + // Data request-related states: + // dataRequests is a map of data request IDs to data request objects. + dataRequests collections.Map[string, types.DataRequest] + // revealBodies is a map of data request IDs and executor public keys to reveal bodies. + revealBodies collections.Map[collections.Pair[string, string], types.RevealBody] + // dataRequestIndexing is a set of data request indices under different statuses. + dataRequestIndexing collections.KeySet[collections.Pair[types.DataRequestStatus, types.DataRequestIndex]] + // timeoutQueue is a queue of data request IDs and their timeout heights. + timeoutQueue collections.KeySet[collections.Pair[int64, string]] + + // Parameter state: + // params defines the core module parameters. + params collections.Item[types.Params] +} + +func NewKeeper( + cdc codec.BinaryCodec, + storeService storetypes.KVStoreService, + wsk types.WasmStorageKeeper, + batk types.BatchingKeeper, + dpk types.DataProxyKeeper, + sk types.StakingKeeper, + bank types.BankKeeper, + wk wasmtypes.ContractOpsKeeper, + wvk wasmtypes.ViewKeeper, + authority string, +) Keeper { + sb := collections.NewSchemaBuilder(storeService) + + k := Keeper{ + wasmStorageKeeper: wsk, + batchingKeeper: batk, + dataProxyKeeper: dpk, + stakingKeeper: sk, + bankKeeper: bank, + wasmKeeper: wk, + wasmViewKeeper: wvk, + authority: authority, + allowlist: collections.NewKeySet(sb, types.AllowlistKey, "allowlist", collections.StringKey), + stakers: collections.NewMap(sb, types.StakersKeyPrefix, "stakers", collections.StringKey, codec.CollValue[types.Staker](cdc)), + dataRequests: collections.NewMap(sb, types.DataRequestsKeyPrefix, "data_requests", collections.StringKey, codec.CollValue[types.DataRequest](cdc)), + revealBodies: collections.NewMap(sb, types.RevealBodiesKeyPrefix, "reveals", collections.PairKeyCodec(collections.StringKey, collections.StringKey), codec.CollValue[types.RevealBody](cdc)), + dataRequestIndexing: collections.NewKeySet(sb, types.DrIndexingKeyPrefix, "data_request_indexing", collections.PairKeyCodec(collcdc.NewInt32Key[types.DataRequestStatus](), collcdc.NewBytesKey[types.DataRequestIndex]())), + timeoutQueue: collections.NewKeySet(sb, types.TimeoutQueueKeyPrefix, "timeout_queue", collections.PairKeyCodec(collections.Int64Key, collections.StringKey)), + params: collections.NewItem(sb, types.ParamsKey, "params", codec.CollValue[types.Params](cdc)), + } + + schema, err := sb.Build() + if err != nil { + panic(err) + } + k.Schema = schema + return k +} + +// GetDataRequest retrieves a data request given its hex-encoded ID. +func (k Keeper) GetDataRequest(ctx sdk.Context, id string) (types.DataRequest, error) { + return k.dataRequests.Get(ctx, id) +} + +// HasDataRequest checks if a data request exists given its hex-encoded ID. +func (k Keeper) HasDataRequest(ctx sdk.Context, id string) (bool, error) { + return k.dataRequests.Has(ctx, id) +} + +// SetDataRequest stores a data request in the store. +func (k Keeper) SetDataRequest(ctx sdk.Context, dr types.DataRequest) error { + return k.dataRequests.Set(ctx, dr.ID, dr) +} + +// RemoveDataRequest removes a data request given its hex-encoded ID. +func (k Keeper) RemoveDataRequest(ctx sdk.Context, id string) error { + return k.dataRequests.Remove(ctx, id) +} + +// GetRevealBody retrieves a reveal body given a data request ID and an executor. +func (k Keeper) GetRevealBody(ctx sdk.Context, drID string, executor string) (types.RevealBody, error) { + return k.revealBodies.Get(ctx, collections.Join(drID, executor)) +} + +// SetRevealBody stores a reveal body in the store. +func (k Keeper) SetRevealBody(ctx sdk.Context, executor string, revealBody types.RevealBody) error { + return k.revealBodies.Set(ctx, collections.Join(revealBody.DrId, executor), revealBody) +} + +// RemoveRevealBodies removes reveal bodies corresponding to a given data request. +func (k Keeper) RemoveRevealBodies(ctx sdk.Context, drID string) error { + iter, err := k.revealBodies.Iterate(ctx, collections.NewPrefixedPairRange[string, string](drID)) + if err != nil { + return err + } + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + key, err := iter.Key() + if err != nil { + return err + } + err = k.revealBodies.Remove(ctx, collections.Join(drID, key.K2())) + if err != nil { + return err + } + } + return nil +} + +// LoadRevealsSorted returns reveals, executors, and gas reports sorted in a +// deterministically random order. The reveals are retrieved based on the given +// map of executors, and each reveal's reported proxy public keys are sorted. +func (k Keeper) LoadRevealsSorted(ctx sdk.Context, drID string, revealsMap map[string]bool) ([]types.Reveal, []string, []uint64) { + reveals := make([]types.Reveal, len(revealsMap)) + i := 0 + for executor := range revealsMap { + revealBody, err := k.GetRevealBody(ctx, drID, executor) + if err != nil { + // TODO Proper error handling + return nil, nil, nil + } + reveals[i] = types.Reveal{Executor: executor, RevealBody: revealBody} + sort.Strings(reveals[i].ProxyPubKeys) + i++ + } + + sortedReveals := types.HashSort(reveals, types.GetEntropy(drID, ctx.BlockHeight())) + + executors := make([]string, len(sortedReveals)) + gasReports := make([]uint64, len(sortedReveals)) + for i, reveal := range sortedReveals { + executors[i] = reveal.Executor + gasReports[i] = reveal.GasUsed + } + return sortedReveals, executors, gasReports +} + +// GetParams retrieves the core module parameters. +func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { + params, err := k.params.Get(ctx) + if err != nil { + return types.Params{}, err + } + return params, nil +} + +// SetParams stores the core module parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + return k.params.Set(ctx, params) +} + +func (k Keeper) GetDataRequestConfig(ctx sdk.Context) (types.DataRequestConfig, error) { + params, err := k.GetParams(ctx) + if err != nil { + return types.DataRequestConfig{}, err + } + return params.DataRequestConfig, nil +} + +func (k Keeper) GetStakingConfig(ctx sdk.Context) (types.StakingConfig, error) { + params, err := k.GetParams(ctx) + if err != nil { + return types.StakingConfig{}, err + } + return params.StakingConfig, nil +} + +func (k Keeper) GetTallyConfig(ctx sdk.Context) (types.TallyConfig, error) { + params, err := k.GetParams(ctx) + if err != nil { + return types.TallyConfig{}, err + } + return params.TallyConfig, nil +} + +func (k Keeper) GetAuthority() string { + return k.authority +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} diff --git a/x/core/keeper/msg_server.go b/x/core/keeper/msg_server.go new file mode 100644 index 00000000..c7df47f5 --- /dev/null +++ b/x/core/keeper/msg_server.go @@ -0,0 +1,165 @@ +package keeper + +import ( + "context" + "encoding/hex" + "errors" + + "cosmossdk.io/collections" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + vrf "github.com/sedaprotocol/vrf-go" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +var _ types.MsgServer = msgServer{} + +type msgServer struct { + Keeper +} + +func NewMsgServerImpl(keeper Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +func (m msgServer) AddToAllowlist(goCtx context.Context, msg *types.MsgAddToAllowlist) (*types.MsgAddToAllowlistResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if msg.Sender != m.GetAuthority() { + return nil, sdkerrors.ErrUnauthorized.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Sender) + } + + exists, err := m.isAllowlisted(ctx, msg.PublicKey) + if err != nil { + return nil, err + } + if exists { + return nil, types.ErrAlreadyAllowlisted + } + + err = m.addToAllowlist(ctx, msg.PublicKey) + if err != nil { + return nil, err + } + + // TODO Add events + + return &types.MsgAddToAllowlistResponse{}, nil +} + +func (m msgServer) Stake(goCtx context.Context, msg *types.MsgStake) (*types.MsgStakeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Verify stake proof. + var sequenceNum uint64 + var isExistingStaker bool // for later use + staker, err := m.GetStaker(ctx, msg.PublicKey) + if err != nil { + if !errors.Is(err, collections.ErrNotFound) { + return nil, err + } + } else { + sequenceNum = staker.SequenceNum + isExistingStaker = true + } + + hash, err := msg.MsgHash("", ctx.ChainID(), sequenceNum) + if err != nil { + return nil, err + } + publicKey, err := hex.DecodeString(msg.PublicKey) + if err != nil { + return nil, err + } + proof, err := hex.DecodeString(msg.Proof) + if err != nil { + return nil, err + } + _, err = vrf.NewK256VRF().Verify(publicKey, proof, hash) + if err != nil { + return nil, types.ErrInvalidStakeProof.Wrapf("%s", err.Error()) + } + + // Verify that the staker is allowlisted if allowlist is enabled. + stakingConfig, err := m.GetStakingConfig(ctx) + if err != nil { + return nil, err + } + if stakingConfig.AllowlistEnabled { + allowlisted, err := m.isAllowlisted(ctx, msg.PublicKey) + if err != nil { + return nil, err + } + if !allowlisted { + return nil, types.ErrNotAllowlisted + } + } + + denom, err := m.stakingKeeper.BondDenom(ctx) + if err != nil { + return nil, err + } + if msg.Stake.Denom != denom { + return nil, sdkerrors.ErrInvalidCoins.Wrapf("invalid denom: %s", msg.Stake.Denom) + } + + // Check stake amount and save the staker. + if isExistingStaker { + staker.Staked = staker.Staked.Add(msg.Stake.Amount) + staker.Memo = msg.Memo + } else { + if msg.Stake.Amount.LT(stakingConfig.MinimumStake) { + return nil, types.ErrInsufficientStake.Wrapf("%s < %s", msg.Stake.Amount, stakingConfig.MinimumStake) + } + staker = types.Staker{ + PublicKey: msg.PublicKey, + Memo: msg.Memo, + Staked: msg.Stake.Amount, + PendingWithdrawal: math.NewInt(0), + SequenceNum: sequenceNum, + } + } + + senderAddr, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + err = m.bankKeeper.SendCoinsFromAccountToModule(ctx, senderAddr, types.ModuleName, sdk.NewCoins(msg.Stake)) + if err != nil { + return nil, err + } + + staker.SequenceNum = sequenceNum + 1 + err = m.SetStaker(ctx, staker) + if err != nil { + return nil, err + } + + // TODO Add events + + return &types.MsgStakeResponse{}, nil +} + +func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", msg.Authority) + } + if m.GetAuthority() != msg.Authority { + return nil, sdkerrors.ErrUnauthorized.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) + } + + if err := msg.Params.Validate(); err != nil { + return nil, err + } + if err := m.SetParams(ctx, msg.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/core/keeper/msg_server_dr.go b/x/core/keeper/msg_server_dr.go new file mode 100644 index 00000000..bf62f363 --- /dev/null +++ b/x/core/keeper/msg_server_dr.go @@ -0,0 +1,295 @@ +package keeper + +import ( + "bytes" + "context" + "encoding/hex" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + vrf "github.com/sedaprotocol/vrf-go" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func (m msgServer) PostDataRequest(goCtx context.Context, msg *types.MsgPostDataRequest) (*types.MsgPostDataRequestResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + drConfig, err := m.GetDataRequestConfig(ctx) + if err != nil { + return nil, err + } + err = msg.Validate(drConfig) + if err != nil { + return nil, err + } + + count, err := m.GetStakersCount(ctx) + if err != nil { + return nil, err + } + maxRF := min(count, types.MaxReplicationFactor) + if msg.ReplicationFactor > maxRF { + return nil, types.ErrReplicationFactorTooHigh.Wrapf("%d > %d", msg.ReplicationFactor, maxRF) + } + + drID, err := msg.MsgHash() + if err != nil { + return nil, err + } + exists, err := m.HasDataRequest(ctx, drID) + if err != nil { + return nil, err + } + if exists { + return nil, types.ErrDataRequestAlreadyExists + } + + denom, err := m.stakingKeeper.BondDenom(ctx) + if err != nil { + return nil, err + } + if msg.Funds.Denom != denom { + return nil, sdkerrors.ErrInvalidCoins.Wrapf("invalid denom: %s", msg.Funds.Denom) + } + + totalGasLimit := math.NewIntFromUint64(msg.ExecGasLimit).Add(math.NewIntFromUint64(msg.TallyGasLimit)) + postedGasPrice := msg.Funds.Amount.Quo(totalGasLimit) + if postedGasPrice.LT(msg.GasPrice) { + requiredFunds, _ := totalGasLimit.SafeMul(msg.GasPrice) + return nil, sdkerrors.ErrInsufficientFunds.Wrapf("required: %s, got %s", requiredFunds, msg.GasPrice) + } + + err = m.bankKeeper.SendCoinsFromAccountToModule( + ctx, + sdk.MustAccAddressFromBech32(msg.Sender), // already validated in msg.Validate() + types.ModuleName, + sdk.NewCoins(msg.Funds), + ) + if err != nil { + return nil, err + } + + dr := types.DataRequest{ + ID: drID, + Version: msg.Version, + ExecProgramID: msg.ExecProgramId, + ExecInputs: msg.ExecInputs, + ExecGasLimit: msg.ExecGasLimit, + TallyProgramID: msg.TallyProgramId, + TallyInputs: msg.TallyInputs, + TallyGasLimit: msg.TallyGasLimit, + ReplicationFactor: msg.ReplicationFactor, + ConsensusFilter: msg.ConsensusFilter, + GasPrice: msg.GasPrice, + Memo: msg.Memo, + PaybackAddress: msg.PaybackAddress, + SEDAPayload: msg.SEDAPayload, + PostedHeight: ctx.BlockHeight(), + PostedGasPrice: postedGasPrice, + Poster: msg.Sender, + Escrow: msg.Funds.Amount, + TimeoutHeight: ctx.BlockHeight() + int64(drConfig.CommitTimeoutInBlocks), + // Commits: make(map[string][]byte), // Dropped by proto anyways + // Reveals: make(map[string]bool), // Dropped by proto anyways + } + + err = m.UpdateDataRequestIndexing(ctx, dr.Index(), dr.Status, types.DATA_REQUEST_STATUS_COMMITTING) + if err != nil { + return nil, err + } + dr.Status = types.DATA_REQUEST_STATUS_COMMITTING + + err = m.AddToTimeoutQueue(ctx, drID, dr.TimeoutHeight) + if err != nil { + return nil, err + } + + err = m.SetDataRequest(ctx, dr) + if err != nil { + return nil, err + } + + // TODO emit events + + return &types.MsgPostDataRequestResponse{ + DrId: drID, + Height: dr.PostedHeight, + }, nil +} + +func (m msgServer) Commit(goCtx context.Context, msg *types.MsgCommit) (*types.MsgCommitResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + params, err := m.GetParams(ctx) + if err != nil { + return nil, err + } + dr, err := m.GetDataRequest(ctx, msg.DrId) + if err != nil { + return nil, err + } + + // Verify the data request status. + if dr.Status != types.DATA_REQUEST_STATUS_COMMITTING { + return nil, types.ErrNotCommitting + } + if _, ok := dr.Commits[msg.PublicKey]; ok { + return nil, types.ErrAlreadyCommitted + } + if dr.TimeoutHeight <= ctx.BlockHeight() { + return nil, types.ErrCommitTimeout + } + + // Verify the staker. + staker, err := m.GetStaker(ctx, msg.PublicKey) + if err != nil { + return nil, err + } + if staker.Staked.LT(params.StakingConfig.MinimumStake) { + return nil, types.ErrInsufficientStake.Wrapf("%s < %s", staker.Staked, params.StakingConfig.MinimumStake) + } + + // Verify the proof. + hash, err := msg.MsgHash("", ctx.ChainID(), dr.PostedHeight) + if err != nil { + return nil, err + } + publicKey, err := hex.DecodeString(msg.PublicKey) + if err != nil { + return nil, err + } + proof, err := hex.DecodeString(msg.Proof) + if err != nil { + return nil, err + } + _, err = vrf.NewK256VRF().Verify(publicKey, proof, hash) + if err != nil { + return nil, types.ErrInvalidCommitProof.Wrapf("%s", err.Error()) + } + + // Store the commit and start reveal phase if the data request is ready. + commit, err := hex.DecodeString(msg.Commit) + if err != nil { + return nil, err + } + dr.AddCommit(msg.PublicKey, commit) + + if len(dr.Commits) >= int(dr.ReplicationFactor) { + newTimeoutHeight := dr.TimeoutHeight + int64(params.DataRequestConfig.RevealTimeoutInBlocks) + err = m.UpdateDataRequestTimeout(ctx, msg.DrId, dr.TimeoutHeight, newTimeoutHeight) + if err != nil { + return nil, err + } + dr.TimeoutHeight = newTimeoutHeight + + err = m.UpdateDataRequestIndexing(ctx, dr.Index(), dr.Status, types.DATA_REQUEST_STATUS_REVEALING) + if err != nil { + return nil, err + } + dr.Status = types.DATA_REQUEST_STATUS_REVEALING + } + + err = m.SetDataRequest(ctx, dr) + if err != nil { + return nil, err + } + + // TODO Refund (ref https://github.com/sedaprotocol/seda-chain/pull/527) + // TODO Emit events + + return &types.MsgCommitResponse{}, nil +} + +func (m msgServer) Reveal(goCtx context.Context, msg *types.MsgReveal) (*types.MsgRevealResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + // Check the status of the data request. + dr, err := m.GetDataRequest(ctx, msg.RevealBody.DrId) + if err != nil { + return nil, err + } + if dr.Status != types.DATA_REQUEST_STATUS_REVEALING { + return nil, types.ErrRevealNotStarted + } + if dr.TimeoutHeight <= ctx.BlockHeight() { + return nil, types.ErrDataRequestExpired.Wrapf("reveal phase expired at height %d", dr.TimeoutHeight) + } + if dr.HasRevealed(msg.PublicKey) { + return nil, types.ErrAlreadyRevealed + } + + commit, exists := dr.GetCommit(msg.PublicKey) + if !exists { + return nil, types.ErrNotCommitted + } + + drConfig, err := m.GetDataRequestConfig(ctx) + if err != nil { + return nil, err + } + err = msg.Validate(drConfig, dr.ReplicationFactor) + if err != nil { + return nil, err + } + + // Verify against the stored commit. + expectedCommit, err := msg.RevealHash() + if err != nil { + return nil, err + } + if !bytes.Equal(commit, expectedCommit) { + return nil, types.ErrRevealMismatch + } + + // Verify the reveal proof. + publicKey, err := hex.DecodeString(msg.PublicKey) + if err != nil { + return nil, err + } + proof, err := hex.DecodeString(msg.Proof) + if err != nil { + return nil, err + } + revealHash, err := msg.MsgHash("", ctx.ChainID()) + if err != nil { + return nil, err + } + _, err = vrf.NewK256VRF().Verify(publicKey, proof, revealHash) + if err != nil { + return nil, types.ErrInvalidRevealProof.Wrapf("%s", err.Error()) + } + + revealsCount := dr.MarkAsRevealed(msg.PublicKey) + if revealsCount >= int(dr.ReplicationFactor) { + // TODO double check + dr.Status = types.DATA_REQUEST_STATUS_TALLYING + + err = m.RemoveFromTimeoutQueue(ctx, dr.ID, dr.TimeoutHeight) + if err != nil { + return nil, err + } + + err = m.UpdateDataRequestIndexing(ctx, dr.Index(), dr.Status, types.DATA_REQUEST_STATUS_TALLYING) + if err != nil { + return nil, err + } + dr.Status = types.DATA_REQUEST_STATUS_TALLYING + } + + err = m.SetRevealBody(ctx, msg.PublicKey, *msg.RevealBody) + if err != nil { + return nil, err + } + err = m.SetDataRequest(ctx, dr) + if err != nil { + return nil, err + } + + // TODO: Add refund logic + // TODO Emit events + + return &types.MsgRevealResponse{}, nil +} diff --git a/x/core/keeper/msg_server_test.go b/x/core/keeper/msg_server_test.go new file mode 100644 index 00000000..e5fa3816 --- /dev/null +++ b/x/core/keeper/msg_server_test.go @@ -0,0 +1,32 @@ +package keeper + +/* TODO Reactivate with other proofs after removing contractAddr. +import ( + "encoding/hex" + "testing" + + "github.com/sedaprotocol/seda-chain/x/core/types" + vrf "github.com/sedaprotocol/vrf-go" + "github.com/stretchr/testify/require" +) + +func TestStakeProof(t *testing.T) { + chainID := "seda-1-devnet" + seqNum := uint64(0) + msg := types.MsgStake{ + PublicKey: "03d92f44157c939284bb101dccea8a2fc95f71ecfd35b44573a76173e3c25c67a9", + // Memo: "", + Proof: "032c74385c590d76e1a6e15364f515f0ae38ba61077c276dcf6aea4a810a36e4988a32cccfd9b08c8ab74f3e4e6dbb6f8e600364432bb166361018f45b817b350b30ae352b7131ab267dffcd643057c483", + } + + hash, err := msg.MsgHash("", chainID, seqNum) + require.NoError(t, err) + publicKey, err := hex.DecodeString(msg.PublicKey) + require.NoError(t, err) + proof, err := hex.DecodeString(msg.Proof) + require.NoError(t, err) + + _, err = vrf.NewK256VRF().Verify(publicKey, proof, hash) + require.NoError(t, err) +} +*/ diff --git a/x/core/keeper/stakers.go b/x/core/keeper/stakers.go new file mode 100644 index 00000000..04bf7579 --- /dev/null +++ b/x/core/keeper/stakers.go @@ -0,0 +1,39 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func (k Keeper) isAllowlisted(ctx sdk.Context, pubKey string) (bool, error) { + return k.allowlist.Has(ctx, pubKey) +} + +func (k Keeper) addToAllowlist(ctx sdk.Context, pubKey string) error { + return k.allowlist.Set(ctx, pubKey) +} + +// GetStaker retrieves a staker given its public key. +func (k Keeper) GetStaker(ctx sdk.Context, pubKey string) (types.Staker, error) { + staker, err := k.stakers.Get(ctx, pubKey) + if err != nil { + return types.Staker{}, err + } + return staker, nil +} + +// SetStaker sets a staker in the store. +func (k Keeper) SetStaker(ctx sdk.Context, staker types.Staker) error { + return k.stakers.Set(ctx, staker.PublicKey, staker) +} + +// GetStakersCount returns the number of stakers in the store. +func (k Keeper) GetStakersCount(ctx sdk.Context) (uint32, error) { + count := uint32(0) + err := k.stakers.Walk(ctx, nil, func(_ string, _ types.Staker) (stop bool, err error) { + count++ + return false, nil + }) + return count, err +} diff --git a/x/tally/types/tally_result.go b/x/core/keeper/tally_result.go similarity index 95% rename from x/tally/types/tally_result.go rename to x/core/keeper/tally_result.go index 95d9a81e..53610971 100644 --- a/x/tally/types/tally_result.go +++ b/x/core/keeper/tally_result.go @@ -1,9 +1,11 @@ -package types +package keeper import ( "sort" "cosmossdk.io/math" + + "github.com/sedaprotocol/seda-chain/x/core/types" ) // TallyResult is used to track results of tally process that are not covered @@ -12,8 +14,8 @@ type TallyResult struct { ID string Height uint64 ReplicationFactor uint16 - Reveals []Reveal - GasMeter *GasMeter + Reveals []types.Reveal + GasMeter *types.GasMeter GasReports []uint64 FilterResult FilterResult StdOut []string diff --git a/x/tally/keeper/tally_vm.go b/x/core/keeper/tally_vm.go similarity index 75% rename from x/tally/keeper/tally_vm.go rename to x/core/keeper/tally_vm.go index 6cd20b5e..0ea1ae71 100644 --- a/x/tally/keeper/tally_vm.go +++ b/x/core/keeper/tally_vm.go @@ -10,11 +10,11 @@ import ( "github.com/sedaprotocol/seda-wasm-vm/tallyvm/v3" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/types" ) type TallyParallelExecItem struct { - Request types.Request + Request types.DataRequest GasMeter *types.GasMeter Reveals []types.Reveal Outliers []bool @@ -25,7 +25,7 @@ type TallyParallelExecItem struct { TallyExecErr error } -func NewTallyParallelExecItem(index int, req types.Request, gasMeter *types.GasMeter, reveals []types.Reveal, outliers []bool, consensus bool) TallyParallelExecItem { +func NewTallyParallelExecItem(index int, req types.DataRequest, gasMeter *types.GasMeter, reveals []types.Reveal, outliers []bool, consensus bool) TallyParallelExecItem { return TallyParallelExecItem{ Index: index, Request: req, @@ -68,22 +68,7 @@ func (k Keeper) ExecuteTallyProgramsParallel(ctx sdk.Context, items []TallyParal continue } - input, err := base64.StdEncoding.DecodeString(items[i].Request.TallyInputs) - if err != nil { - items[i].TallyExecErr = err - k.Logger(ctx).Error(err.Error(), "request_id", items[i].Request.ID, "error", types.ErrDecodingTallyInputs) - continue - } - - // Convert base64 payback address to hex that tally VM expects. - paybackAddrBytes, err := base64.StdEncoding.DecodeString(items[i].Request.PaybackAddress) - if err != nil { - items[i].TallyExecErr = err - k.Logger(ctx).Error(err.Error(), "request_id", items[i].Request.ID, "error", types.ErrDecodingPaybackAddress) - continue - } - - arg, err := tallyVMArg(input, items[i].Reveals, items[i].Outliers) + arg, err := tallyVMArg(items[i].Request.TallyInputs, items[i].Reveals, items[i].Outliers) if err != nil { items[i].TallyExecErr = err k.Logger(ctx).Error(err.Error(), "request_id", items[i].Request.ID, "error", types.ErrConstructingTallyVMArgs) @@ -99,14 +84,14 @@ func (k Keeper) ExecuteTallyProgramsParallel(ctx sdk.Context, items []TallyParal "DR_ID": items[i].Request.ID, "DR_REPLICATION_FACTOR": fmt.Sprintf("%v", items[i].Request.ReplicationFactor), "EXEC_PROGRAM_ID": items[i].Request.ExecProgramID, - "EXEC_INPUTS": items[i].Request.ExecInputs, + "EXEC_INPUTS": base64.StdEncoding.EncodeToString(items[i].Request.ExecInputs), "EXEC_GAS_LIMIT": fmt.Sprintf("%v", items[i].Request.ExecGasLimit), - "TALLY_INPUTS": items[i].Request.TallyInputs, + "TALLY_INPUTS": base64.StdEncoding.EncodeToString(items[i].Request.TallyInputs), "TALLY_PROGRAM_ID": items[i].Request.TallyProgramID, "DR_TALLY_GAS_LIMIT": fmt.Sprintf("%v", items[i].GasMeter.RemainingTallyGas()), - "DR_GAS_PRICE": items[i].Request.PostedGasPrice, - "DR_MEMO": items[i].Request.Memo, - "DR_PAYBACK_ADDRESS": hex.EncodeToString(paybackAddrBytes), + "DR_GAS_PRICE": items[i].Request.PostedGasPrice.String(), + "DR_MEMO": base64.StdEncoding.EncodeToString(items[i].Request.Memo), + "DR_PAYBACK_ADDRESS": hex.EncodeToString(items[i].Request.PaybackAddress), }) k.Logger(ctx).Debug( diff --git a/x/tally/keeper/tally_vm_test.go b/x/core/keeper/tally_vm_test.go similarity index 73% rename from x/tally/keeper/tally_vm_test.go rename to x/core/keeper/tally_vm_test.go index 6e11094b..7f011a60 100644 --- a/x/tally/keeper/tally_vm_test.go +++ b/x/core/keeper/tally_vm_test.go @@ -1,5 +1,7 @@ package keeper_test +/* Turned off until x/core endblock implementation is complete + import ( "encoding/base64" "encoding/hex" @@ -14,8 +16,8 @@ import ( "github.com/sedaprotocol/seda-wasm-vm/tallyvm/v3" "github.com/sedaprotocol/seda-chain/testutil/testwasms" - "github.com/sedaprotocol/seda-chain/x/tally/keeper" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/keeper" + "github.com/sedaprotocol/seda-chain/x/core/types" wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" ) @@ -29,10 +31,11 @@ func TestExecuteTallyProgram_RandomString(t *testing.T) { execItems := []keeper.TallyParallelExecItem{ { - Request: types.Request{ - TallyProgramID: hex.EncodeToString(tallyProgram.Hash), - TallyInputs: base64.StdEncoding.EncodeToString([]byte("hello")), - PaybackAddress: base64.StdEncoding.EncodeToString([]byte("0x0")), +<<<<<<< HEAD + Request: types.DataRequest{ + TallyProgramId: hex.EncodeToString(tallyProgram.Hash), + TallyInputs: []byte("hello"), + PaybackAddress: []byte("0x0"), }, Reveals: []types.Reveal{ { @@ -59,13 +62,40 @@ func TestExecuteTallyProgram_RandomString(t *testing.T) { GasUsed: 10, }, }, +======= + Executor: "0", + RevealBody: types.RevealBody{ + Reveal: []byte("{\"value\":\"one\"}"), + ProxyPubKeys: []string{}, + GasUsed: 10, + }, + }, + { + Executor: "1", + RevealBody: types.RevealBody{ + Reveal: []byte("{\"value\":\"two\"}"), + ProxyPubKeys: []string{}, + GasUsed: 10, +>>>>>>> 7f9067a (chore(x/core): addressing review comments) }, Outliers: []bool{false, true, false}, GasMeter: types.NewGasMeter(types.DefaultMaxTallyGasLimit, 100, types.DefaultMaxTallyGasLimit, math.NewInt(1), 1), }, +<<<<<<< HEAD } +======= + { + Executor: "2", + RevealBody: types.RevealBody{ + Reveal: []byte("{\"value\":\"three\"}"), + ProxyPubKeys: []string{}, + GasUsed: 10, + }, + }, + }, gasMeter) +>>>>>>> 7f9067a (chore(x/core): addressing review comments) - vmRes := f.tallyKeeper.ExecuteTallyProgramsParallel(f.Context(), execItems) + vmRes := f.keeper.ExecuteTallyProgramsParallel(f.Context(), execItems) require.NoError(t, execItems[0].TallyExecErr) require.Equal(t, 1, len(vmRes)) @@ -85,10 +115,10 @@ func TestExecuteTallyProgram_InvalidImports(t *testing.T) { execItems := []keeper.TallyParallelExecItem{ { - Request: types.Request{ - TallyProgramID: hex.EncodeToString(tallyProgram.Hash), - TallyInputs: base64.StdEncoding.EncodeToString([]byte("hello")), - PaybackAddress: base64.StdEncoding.EncodeToString([]byte("0x0")), + Request: types.DataRequest{ + TallyProgramId: hex.EncodeToString(tallyProgram.Hash), + TallyInputs: []byte("hello"), + PaybackAddress: []byte("0x0"), }, Reveals: []types.Reveal{}, Outliers: []bool{}, @@ -96,7 +126,7 @@ func TestExecuteTallyProgram_InvalidImports(t *testing.T) { }, } - vmRes := f.tallyKeeper.ExecuteTallyProgramsParallel(f.Context(), execItems) + vmRes := f.keeper.ExecuteTallyProgramsParallel(f.Context(), execItems) require.NoError(t, execItems[0].TallyExecErr) require.Equal(t, 1, len(vmRes)) @@ -128,24 +158,9 @@ func TestTallyVM(t *testing.T) { "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" - } + "1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":true, + "1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":true, + "421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":true }, "seda_payload":"", "tally_program_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b", @@ -170,24 +185,9 @@ func TestTallyVM(t *testing.T) { "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" - } + "1b85dfb9420e6757630a0db2280fa1787ec8c1e419a6aca76dbbfe8ef6e17521":true, + "1dae290cd880b79d21079d89aee3460cf8a7d445fb35cade70cf8aa96924441c":true, + "421e735518ef77fc1209a9d3585cdf096669b52ea68549e2ce048d4919b4c8c0":true }, "seda_payload":"", "tally_program_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b", @@ -212,12 +212,7 @@ func TestTallyVM(t *testing.T) { "payback_address":"", "replication_factor":1, "reveals":{ - "c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":{ - "exit_code":0, - "gas_used":10, - "reveal":"Yw==", - "salt":"f837455a930a66464f1c50586dc745a6b14ea807727c6069acac24c9558b6dbf" - } + "c9a4c8f1e70a0059a88b4768a920e41c95c587b8387ea3286d8fa4ee3b68b038":true }, "seda_payload":"", "tally_program_id":"8ade60039246740faa80bf424fc29e79fe13b32087043e213e7bc36620111f6b", @@ -232,25 +227,25 @@ func TestTallyVM(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - var req types.Request - err := json.Unmarshal(tc.requestJSON, &req) + var dr types.DataRequest + err := json.Unmarshal(tc.requestJSON, &dr) require.NoError(t, err) result := tallyvm.ExecuteTallyVm(testwasms.SampleTallyWasm(), tc.args, map[string]string{ "VM_MODE": "tally", "CONSENSUS": fmt.Sprintf("%v", true), "BLOCK_HEIGHT": fmt.Sprintf("%d", 1), - "DR_ID": req.ID, - "EXEC_PROGRAM_ID": req.ExecProgramID, - "EXEC_INPUTS": req.ExecInputs, - "EXEC_GAS_LIMIT": fmt.Sprintf("%v", req.ExecGasLimit), - "TALLY_INPUTS": req.TallyInputs, - "TALLY_PROGRAM_ID": req.TallyProgramID, - "DR_REPLICATION_FACTOR": fmt.Sprintf("%v", req.ReplicationFactor), - "DR_GAS_PRICE": req.PostedGasPrice, - "DR_TALLY_GAS_LIMIT": fmt.Sprintf("%v", req.TallyGasLimit), - "DR_MEMO": req.Memo, - "DR_PAYBACK_ADDRESS": req.PaybackAddress, + "DR_ID": dr.Id, + "EXEC_PROGRAM_ID": dr.ExecProgramId, + "EXEC_INPUTS": base64.StdEncoding.EncodeToString(dr.ExecInputs), + "EXEC_GAS_LIMIT": fmt.Sprintf("%d", dr.ExecGasLimit), + "TALLY_INPUTS": base64.StdEncoding.EncodeToString(dr.TallyInputs), + "TALLY_PROGRAM_ID": dr.TallyProgramId, + "DR_REPLICATION_FACTOR": fmt.Sprintf("%d", dr.ReplicationFactor), + "DR_GAS_PRICE": dr.PostedGasPrice.String(), + "DR_TALLY_GAS_LIMIT": fmt.Sprintf("%d", dr.TallyGasLimit), + "DR_MEMO": base64.StdEncoding.EncodeToString(dr.Memo), + "DR_PAYBACK_ADDRESS": hex.EncodeToString(dr.PaybackAddress), }) if tc.expErr != "" { @@ -285,7 +280,7 @@ func TestTallyVM_EnvVars(t *testing.T) { "gas_price":"10", "height":1661661742461173200, "id":"fba5314c57e52da7d1a2245d18c670fde1cb8c237062d2a1be83f449ace0932e", - "memo":"mock_data_request_num_one", + "memo":"", "payback_address":"YrzimoSJXwpA7ju71AkhkirkDCU=", "consensus_filter":"AQAAAAAAAAALcmVzdWx0LnRleHQ=", "replication_factor":3, @@ -301,25 +296,25 @@ func TestTallyVM_EnvVars(t *testing.T) { for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { - var req types.Request - err := json.Unmarshal(tc.requestJSON, &req) + var dr types.DataRequest + err := json.Unmarshal(tc.requestJSON, &dr) require.NoError(t, err) envs := map[string]string{ "VM_MODE": "tally", "CONSENSUS": fmt.Sprintf("%v", true), "BLOCK_HEIGHT": fmt.Sprintf("%d", 1), - "DR_ID": req.ID, - "EXEC_PROGRAM_ID": req.ExecProgramID, - "EXEC_INPUTS": req.ExecInputs, - "EXEC_GAS_LIMIT": fmt.Sprintf("%v", req.ExecGasLimit), - "TALLY_INPUTS": req.TallyInputs, - "TALLY_PROGRAM_ID": req.TallyProgramID, - "DR_REPLICATION_FACTOR": fmt.Sprintf("%v", req.ReplicationFactor), - "DR_GAS_PRICE": req.PostedGasPrice, - "DR_TALLY_GAS_LIMIT": fmt.Sprintf("%v", req.TallyGasLimit), - "DR_MEMO": req.Memo, - "DR_PAYBACK_ADDRESS": req.PaybackAddress, + "DR_ID": dr.Id, + "EXEC_PROGRAM_ID": dr.ExecProgramId, + "EXEC_INPUTS": base64.StdEncoding.EncodeToString(dr.ExecInputs), + "EXEC_GAS_LIMIT": fmt.Sprintf("%d", dr.ExecGasLimit), + "TALLY_INPUTS": base64.StdEncoding.EncodeToString(dr.TallyInputs), + "TALLY_PROGRAM_ID": dr.TallyProgramId, + "DR_REPLICATION_FACTOR": fmt.Sprintf("%d", dr.ReplicationFactor), + "DR_GAS_PRICE": dr.PostedGasPrice.String(), + "DR_TALLY_GAS_LIMIT": fmt.Sprintf("%d", dr.TallyGasLimit), + "DR_MEMO": base64.StdEncoding.EncodeToString(dr.Memo), + "DR_PAYBACK_ADDRESS": hex.EncodeToString(dr.PaybackAddress), } result := tallyvm.ExecuteTallyVm(testwasms.SampleTallyWasm2(), tc.args, envs) @@ -347,11 +342,11 @@ func TestExecuteTallyProgramsParallel_ErrorHandling(t *testing.T) { execItems := []keeper.TallyParallelExecItem{ { Index: 0, - Request: types.Request{ - ID: "some_id_0", - TallyProgramID: hex.EncodeToString(validProgram.Hash), - TallyInputs: base64.StdEncoding.EncodeToString([]byte("some_tally_input")), - PaybackAddress: base64.StdEncoding.EncodeToString([]byte("0x1111")), + Request: types.DataRequest{ + Id: "some_id_0", + TallyProgramId: hex.EncodeToString(validProgram.Hash), + TallyInputs: []byte("some_tally_input"), + PaybackAddress: []byte("0x1111"), }, Reveals: []types.Reveal{ { @@ -369,27 +364,27 @@ func TestExecuteTallyProgramsParallel_ErrorHandling(t *testing.T) { }, { Index: 1, - Request: types.Request{ - ID: "some_id_1", - TallyProgramID: "non_existent_program_hash", // This will cause an error + Request: types.DataRequest{ + Id: "some_id_1", + TallyProgramId: "non_existent_program_hash", // This will cause an error }, }, { Index: 2, - Request: types.Request{ - ID: "some_id_2", - TallyProgramID: hex.EncodeToString(validProgram.Hash), - TallyInputs: base64.StdEncoding.EncodeToString([]byte("some_tally_input")), - PaybackAddress: "invalid_base64_payback_address", // This will cause an error + Request: types.DataRequest{ + Id: "some_id_2", + TallyProgramId: hex.EncodeToString(validProgram.Hash), + TallyInputs: []byte("some_tally_input"), + PaybackAddress: []byte("invalid_base64_payback_address"), // This will cause an error }, }, { Index: 3, - Request: types.Request{ - ID: "some_id_3", - TallyProgramID: hex.EncodeToString(validProgram.Hash), - TallyInputs: base64.StdEncoding.EncodeToString([]byte("some_tally_input")), - PaybackAddress: base64.StdEncoding.EncodeToString([]byte("0x1111")), + Request: types.DataRequest{ + Id: "some_id_3", + TallyProgramId: hex.EncodeToString(validProgram.Hash), + TallyInputs: []byte("some_tally_input"), + PaybackAddress: []byte("0x1111"), }, Reveals: []types.Reveal{ { @@ -407,7 +402,7 @@ func TestExecuteTallyProgramsParallel_ErrorHandling(t *testing.T) { }, } - vmResults := f.tallyKeeper.ExecuteTallyProgramsParallel(f.Context(), execItems) + vmResults := f.keeper.ExecuteTallyProgramsParallel(f.Context(), execItems) require.Equal(t, 2, len(vmResults), "Should return results only for valid execution items") @@ -416,3 +411,4 @@ func TestExecuteTallyProgramsParallel_ErrorHandling(t *testing.T) { require.Contains(t, execItems[2].TallyExecErr.Error(), "illegal base64 data") require.NoError(t, execItems[3].TallyExecErr, "Valid item should have no error") } +*/ diff --git a/x/core/keeper/timeout_queue.go b/x/core/keeper/timeout_queue.go new file mode 100644 index 00000000..1c79b842 --- /dev/null +++ b/x/core/keeper/timeout_queue.go @@ -0,0 +1,86 @@ +package keeper + +import ( + "fmt" + + "cosmossdk.io/collections" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func (k Keeper) AddToTimeoutQueue(ctx sdk.Context, drID string, timeoutHeight int64) error { + return k.timeoutQueue.Set(ctx, collections.Join(timeoutHeight, drID)) +} + +func (k Keeper) RemoveFromTimeoutQueue(ctx sdk.Context, drID string, timeoutHeight int64) error { + err := k.timeoutQueue.Remove(ctx, collections.Join(timeoutHeight, drID)) + if err != nil { + return err + } + return nil +} + +func (k Keeper) UpdateDataRequestTimeout(ctx sdk.Context, drID string, oldTimeoutHeight, newTimeoutHeight int64) error { + exists, err := k.timeoutQueue.Has(ctx, collections.Join(oldTimeoutHeight, drID)) + if err != nil { + return err + } + if !exists { + return fmt.Errorf("data request %s not found in timeout queue", drID) + } + err = k.timeoutQueue.Remove(ctx, collections.Join(oldTimeoutHeight, drID)) + if err != nil { + return err + } + return k.timeoutQueue.Set(ctx, collections.Join(newTimeoutHeight, drID)) +} + +func (k Keeper) ExpireDataRequests(ctx sdk.Context) error { + iter, err := k.timeoutQueue.Iterate(ctx, nil) + if err != nil { + return err + } + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + key, err := iter.Key() + if err != nil { + return err + } + timeoutHeight := key.K1() + drID := key.K2() + + if timeoutHeight > ctx.BlockHeight() { + break + } + + // Update data request status to tallying. + dr, err := k.GetDataRequest(ctx, drID) + if err != nil { + return err + } + + err = k.UpdateDataRequestIndexing(ctx, dr.Index(), dr.Status, types.DATA_REQUEST_STATUS_TALLYING) + if err != nil { + return err + } + dr.Status = types.DATA_REQUEST_STATUS_TALLYING + dr.TimeoutHeight = -1 + + err = k.SetDataRequest(ctx, dr) + if err != nil { + return err + } + + // Remove from timeout queue. + err = k.timeoutQueue.Remove(ctx, key) + if err != nil { + return err + } + k.Logger(ctx).Debug("expired data request", "ID", drID) + } + + return nil +} diff --git a/x/tally/module.go b/x/core/module.go similarity index 95% rename from x/tally/module.go rename to x/core/module.go index 49ca5f62..10a906b1 100644 --- a/x/tally/module.go +++ b/x/core/module.go @@ -1,4 +1,4 @@ -package tally +package core import ( "context" @@ -17,9 +17,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - "github.com/sedaprotocol/seda-chain/x/tally/client/cli" - "github.com/sedaprotocol/seda-chain/x/tally/keeper" - "github.com/sedaprotocol/seda-chain/x/tally/types" + "github.com/sedaprotocol/seda-chain/x/core/client/cli" + "github.com/sedaprotocol/seda-chain/x/core/keeper" + "github.com/sedaprotocol/seda-chain/x/core/types" ) var ( @@ -70,7 +70,7 @@ func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { return cdc.MustMarshalJSON(types.DefaultGenesisState()) } -// ValidateGenesis performs genesis state validation for the tally module. +// ValidateGenesis performs genesis state validation for the core module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { var data types.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { @@ -144,7 +144,7 @@ func (am AppModule) BeginBlock(_ context.Context) error { return nil } -// EndBlock returns the end block logic for the tally module. +// EndBlock returns the end block logic for the core module. func (am AppModule) EndBlock(ctx context.Context) error { start := telemetry.Now() defer telemetry.ModuleMeasureSince(types.ModuleName, start, telemetry.MetricKeyEndBlocker) diff --git a/x/tally/types/codec.go b/x/core/types/codec.go similarity index 100% rename from x/tally/types/codec.go rename to x/core/types/codec.go diff --git a/x/core/types/core.pb.go b/x/core/types/core.pb.go new file mode 100644 index 00000000..86a6be51 --- /dev/null +++ b/x/core/types/core.pb.go @@ -0,0 +1,3860 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sedachain/core/v1/core.proto + +package types + +import ( + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// DataRequestStatus is the status of a data request. +type DataRequestStatus int32 + +const ( + // Zero value as required by proto3. + DATA_REQUEST_STATUS_UNSPECIFIED DataRequestStatus = 0 + // Data request has been posted and is collecting commits. + DATA_REQUEST_STATUS_COMMITTING DataRequestStatus = 1 + // The number of commits has reached the replication factor, and the data + // request is now collecting reveals. + DATA_REQUEST_STATUS_REVEALING DataRequestStatus = 2 + // The number of reveals has reached the replication factor, and the data + // request is now ready to be tallied. + DATA_REQUEST_STATUS_TALLYING DataRequestStatus = 3 +) + +var DataRequestStatus_name = map[int32]string{ + 0: "DATA_REQUEST_STATUS_UNSPECIFIED", + 1: "DATA_REQUEST_STATUS_COMMITTING", + 2: "DATA_REQUEST_STATUS_REVEALING", + 3: "DATA_REQUEST_STATUS_TALLYING", +} + +var DataRequestStatus_value = map[string]int32{ + "DATA_REQUEST_STATUS_UNSPECIFIED": 0, + "DATA_REQUEST_STATUS_COMMITTING": 1, + "DATA_REQUEST_STATUS_REVEALING": 2, + "DATA_REQUEST_STATUS_TALLYING": 3, +} + +func (x DataRequestStatus) String() string { + return proto.EnumName(DataRequestStatus_name, int32(x)) +} + +func (DataRequestStatus) EnumDescriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{0} +} + +// Staker is an identity that has staked SEDA tokens to perform data request +// execution. +type Staker struct { + PublicKey string `protobuf:"bytes,1,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + Memo string `protobuf:"bytes,2,opt,name=memo,proto3" json:"memo,omitempty"` + Staked cosmossdk_io_math.Int `protobuf:"bytes,3,opt,name=staked,proto3,customtype=cosmossdk.io/math.Int" json:"staked"` + PendingWithdrawal cosmossdk_io_math.Int `protobuf:"bytes,4,opt,name=pending_withdrawal,json=pendingWithdrawal,proto3,customtype=cosmossdk.io/math.Int" json:"pending_withdrawal"` + SequenceNum uint64 `protobuf:"varint,5,opt,name=sequence_num,json=sequenceNum,proto3" json:"sequence_num,omitempty"` +} + +func (m *Staker) Reset() { *m = Staker{} } +func (m *Staker) String() string { return proto.CompactTextString(m) } +func (*Staker) ProtoMessage() {} +func (*Staker) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{0} +} +func (m *Staker) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Staker) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Staker.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Staker) XXX_Merge(src proto.Message) { + xxx_messageInfo_Staker.Merge(m, src) +} +func (m *Staker) XXX_Size() int { + return m.Size() +} +func (m *Staker) XXX_DiscardUnknown() { + xxx_messageInfo_Staker.DiscardUnknown(m) +} + +var xxx_messageInfo_Staker proto.InternalMessageInfo + +func (m *Staker) GetPublicKey() string { + if m != nil { + return m.PublicKey + } + return "" +} + +func (m *Staker) GetMemo() string { + if m != nil { + return m.Memo + } + return "" +} + +func (m *Staker) GetSequenceNum() uint64 { + if m != nil { + return m.SequenceNum + } + return 0 +} + +// DataRequest is a data request object. +type DataRequest struct { + // Hex-encoded ID of the data request + ID string `protobuf:"bytes,1,opt,name=i_d,json=iD,proto3" json:"id"` + // Semantic versioning + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + // Hex-encoded ID (hash) of the execution program + ExecProgramID string `protobuf:"bytes,3,opt,name=exec_program_i_d,json=execProgramID,proto3" json:"exec_program_id"` + // Inputs for the execution program + ExecInputs []byte `protobuf:"bytes,4,opt,name=exec_inputs,json=execInputs,proto3" json:"exec_inputs,omitempty"` + // Gas limit for execution program execution + ExecGasLimit uint64 `protobuf:"varint,5,opt,name=exec_gas_limit,json=execGasLimit,proto3" json:"exec_gas_limit,omitempty"` + // Hex-encoded ID (hash) of the tally program + TallyProgramID string `protobuf:"bytes,6,opt,name=tally_program_i_d,json=tallyProgramID,proto3" json:"tally_program_id"` + // Inputs for the tally program + TallyInputs []byte `protobuf:"bytes,7,opt,name=tally_inputs,json=tallyInputs,proto3" json:"tally_inputs,omitempty"` + // Gas limit for tally program execution + TallyGasLimit uint64 `protobuf:"varint,8,opt,name=tally_gas_limit,json=tallyGasLimit,proto3" json:"tally_gas_limit,omitempty"` + // Number of required data request executors (used as uint16) + ReplicationFactor uint32 `protobuf:"varint,9,opt,name=replication_factor,json=replicationFactor,proto3" json:"replication_factor,omitempty"` + // Specifications for the filter process + ConsensusFilter []byte `protobuf:"bytes,10,opt,name=consensus_filter,json=consensusFilter,proto3" json:"consensus_filter,omitempty"` + // Amount of SEDA tokens per unit gas (used as uint128) + GasPrice cosmossdk_io_math.Int `protobuf:"bytes,11,opt,name=gas_price,json=gasPrice,proto3,customtype=cosmossdk.io/math.Int" json:"gas_price"` + // Public information attached to the data request + Memo []byte `protobuf:"bytes,12,opt,name=memo,proto3" json:"memo,omitempty"` + // Set by the relayer + PaybackAddress []byte `protobuf:"bytes,13,opt,name=payback_address,json=paybackAddress,proto3" json:"payback_address,omitempty"` + // Set by SEDA Protocol (e.g. OEV-enabled data requests) + SEDAPayload []byte `protobuf:"bytes,14,opt,name=s_e_d_a_payload,json=sEDAPayload,proto3" json:"s_e_d_a_payload,omitempty"` + // Height at which the data request was posted + PostedHeight int64 `protobuf:"varint,15,opt,name=posted_height,json=postedHeight,proto3" json:"posted_height,omitempty"` + // Actual gas price derived by dividing attached funds by the total gas limit + // (may be higher than the minimum gas price) + PostedGasPrice cosmossdk_io_math.Int `protobuf:"bytes,16,opt,name=posted_gas_price,json=postedGasPrice,proto3,customtype=cosmossdk.io/math.Int" json:"posted_gas_price"` + // Map from staker public keys to commits. + Commits map[string][]byte `protobuf:"bytes,17,rep,name=commits,proto3" json:"commits,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // Map from staker public keys to placeholder booleans. + Reveals map[string]bool `protobuf:"bytes,18,rep,name=reveals,proto3" json:"reveals,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` + // Poster of the data request (Bech32 string) + Poster string `protobuf:"bytes,19,opt,name=poster,proto3" json:"poster,omitempty"` + // Funds escrowed for the data request + Escrow cosmossdk_io_math.Int `protobuf:"bytes,20,opt,name=escrow,proto3,customtype=cosmossdk.io/math.Int" json:"escrow"` + // Timeout height of the data request (-1 if not set, i.e., under tallying + // status) + TimeoutHeight int64 `protobuf:"varint,21,opt,name=timeout_height,json=timeoutHeight,proto3" json:"timeout_height,omitempty"` + // Status of the data request + Status DataRequestStatus `protobuf:"varint,22,opt,name=status,proto3,enum=sedachain.core.v1.DataRequestStatus" json:"status,omitempty"` +} + +func (m *DataRequest) Reset() { *m = DataRequest{} } +func (m *DataRequest) String() string { return proto.CompactTextString(m) } +func (*DataRequest) ProtoMessage() {} +func (*DataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{1} +} +func (m *DataRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DataRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_DataRequest.Merge(m, src) +} +func (m *DataRequest) XXX_Size() int { + return m.Size() +} +func (m *DataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_DataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_DataRequest proto.InternalMessageInfo + +func (m *DataRequest) GetID() string { + if m != nil { + return m.ID + } + return "" +} + +func (m *DataRequest) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +func (m *DataRequest) GetExecProgramID() string { + if m != nil { + return m.ExecProgramID + } + return "" +} + +func (m *DataRequest) GetExecInputs() []byte { + if m != nil { + return m.ExecInputs + } + return nil +} + +func (m *DataRequest) GetExecGasLimit() uint64 { + if m != nil { + return m.ExecGasLimit + } + return 0 +} + +func (m *DataRequest) GetTallyProgramID() string { + if m != nil { + return m.TallyProgramID + } + return "" +} + +func (m *DataRequest) GetTallyInputs() []byte { + if m != nil { + return m.TallyInputs + } + return nil +} + +func (m *DataRequest) GetTallyGasLimit() uint64 { + if m != nil { + return m.TallyGasLimit + } + return 0 +} + +func (m *DataRequest) GetReplicationFactor() uint32 { + if m != nil { + return m.ReplicationFactor + } + return 0 +} + +func (m *DataRequest) GetConsensusFilter() []byte { + if m != nil { + return m.ConsensusFilter + } + return nil +} + +func (m *DataRequest) GetMemo() []byte { + if m != nil { + return m.Memo + } + return nil +} + +func (m *DataRequest) GetPaybackAddress() []byte { + if m != nil { + return m.PaybackAddress + } + return nil +} + +func (m *DataRequest) GetSEDAPayload() []byte { + if m != nil { + return m.SEDAPayload + } + return nil +} + +func (m *DataRequest) GetPostedHeight() int64 { + if m != nil { + return m.PostedHeight + } + return 0 +} + +func (m *DataRequest) GetCommits() map[string][]byte { + if m != nil { + return m.Commits + } + return nil +} + +func (m *DataRequest) GetReveals() map[string]bool { + if m != nil { + return m.Reveals + } + return nil +} + +func (m *DataRequest) GetPoster() string { + if m != nil { + return m.Poster + } + return "" +} + +func (m *DataRequest) GetTimeoutHeight() int64 { + if m != nil { + return m.TimeoutHeight + } + return 0 +} + +func (m *DataRequest) GetStatus() DataRequestStatus { + if m != nil { + return m.Status + } + return DATA_REQUEST_STATUS_UNSPECIFIED +} + +// RevealBody is the content of a reveal. +type RevealBody struct { + // Hex-encoded ID of the data request + DrId string `protobuf:"bytes,1,opt,name=dr_id,json=drId,proto3" json:"dr_id,omitempty"` + // Block height of the data request posting + DrBlockHeight uint64 `protobuf:"varint,2,opt,name=dr_block_height,json=drBlockHeight,proto3" json:"dr_block_height,omitempty"` + // Exit code of the data request execution (used as uint8) + ExitCode uint32 `protobuf:"varint,3,opt,name=exit_code,json=exitCode,proto3" json:"exit_code,omitempty"` + // Gas used by the data request execution + GasUsed uint64 `protobuf:"varint,4,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"` + // Contents of the reveal + Reveal []byte `protobuf:"bytes,5,opt,name=reveal,proto3" json:"reveal,omitempty"` + // List of data proxy public keys used + ProxyPubKeys []string `protobuf:"bytes,6,rep,name=proxy_pub_keys,json=proxyPubKeys,proto3" json:"proxy_public_keys"` +} + +func (m *RevealBody) Reset() { *m = RevealBody{} } +func (m *RevealBody) String() string { return proto.CompactTextString(m) } +func (*RevealBody) ProtoMessage() {} +func (*RevealBody) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{2} +} +func (m *RevealBody) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *RevealBody) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_RevealBody.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *RevealBody) XXX_Merge(src proto.Message) { + xxx_messageInfo_RevealBody.Merge(m, src) +} +func (m *RevealBody) XXX_Size() int { + return m.Size() +} +func (m *RevealBody) XXX_DiscardUnknown() { + xxx_messageInfo_RevealBody.DiscardUnknown(m) +} + +var xxx_messageInfo_RevealBody proto.InternalMessageInfo + +func (m *RevealBody) GetDrId() string { + if m != nil { + return m.DrId + } + return "" +} + +func (m *RevealBody) GetDrBlockHeight() uint64 { + if m != nil { + return m.DrBlockHeight + } + return 0 +} + +func (m *RevealBody) GetExitCode() uint32 { + if m != nil { + return m.ExitCode + } + return 0 +} + +func (m *RevealBody) GetGasUsed() uint64 { + if m != nil { + return m.GasUsed + } + return 0 +} + +func (m *RevealBody) GetReveal() []byte { + if m != nil { + return m.Reveal + } + return nil +} + +func (m *RevealBody) GetProxyPubKeys() []string { + if m != nil { + return m.ProxyPubKeys + } + return nil +} + +// Params defines the parameters for the core module. +type Params struct { + DataRequestConfig DataRequestConfig `protobuf:"bytes,1,opt,name=data_request_config,json=dataRequestConfig,proto3" json:"data_request_config"` + StakingConfig StakingConfig `protobuf:"bytes,2,opt,name=staking_config,json=stakingConfig,proto3" json:"staking_config"` + TallyConfig TallyConfig `protobuf:"bytes,3,opt,name=tally_config,json=tallyConfig,proto3" json:"tally_config"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{3} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetDataRequestConfig() DataRequestConfig { + if m != nil { + return m.DataRequestConfig + } + return DataRequestConfig{} +} + +func (m *Params) GetStakingConfig() StakingConfig { + if m != nil { + return m.StakingConfig + } + return StakingConfig{} +} + +func (m *Params) GetTallyConfig() TallyConfig { + if m != nil { + return m.TallyConfig + } + return TallyConfig{} +} + +// DataRequestConfig defines data request-related parameters. +type DataRequestConfig struct { + // Number of blocks after which a data request is timed out while waiting + // for commits. + CommitTimeoutInBlocks uint32 `protobuf:"varint,1,opt,name=commit_timeout_in_blocks,json=commitTimeoutInBlocks,proto3" json:"commit_timeout_in_blocks,omitempty"` + // Number of blocks after which a data request is timed out while waiting + // for reveals. + RevealTimeoutInBlocks uint32 `protobuf:"varint,2,opt,name=reveal_timeout_in_blocks,json=revealTimeoutInBlocks,proto3" json:"reveal_timeout_in_blocks,omitempty"` + // Delay in blocks before the backup executors are allowed to start executing + // the data request. + BackupDelayInBlocks uint32 `protobuf:"varint,3,opt,name=backup_delay_in_blocks,json=backupDelayInBlocks,proto3" json:"backup_delay_in_blocks,omitempty"` + // Maximum size of all the reveals in a data request. + DrRevealSizeLimitInBytes uint32 `protobuf:"varint,4,opt,name=dr_reveal_size_limit_in_bytes,json=drRevealSizeLimitInBytes,proto3" json:"dr_reveal_size_limit_in_bytes,omitempty"` + // Maximum size of the input for the execution program. + ExecInputLimitInBytes uint32 `protobuf:"varint,5,opt,name=exec_input_limit_in_bytes,json=execInputLimitInBytes,proto3" json:"exec_input_limit_in_bytes,omitempty"` + // Maximum size of the input for the tally program. + TallyInputLimitInBytes uint32 `protobuf:"varint,6,opt,name=tally_input_limit_in_bytes,json=tallyInputLimitInBytes,proto3" json:"tally_input_limit_in_bytes,omitempty"` + // Maximum size of the consensus filter. + ConsensusFilterLimitInBytes uint32 `protobuf:"varint,7,opt,name=consensus_filter_limit_in_bytes,json=consensusFilterLimitInBytes,proto3" json:"consensus_filter_limit_in_bytes,omitempty"` + // Maximum size of the memo. + MemoLimitInBytes uint32 `protobuf:"varint,8,opt,name=memo_limit_in_bytes,json=memoLimitInBytes,proto3" json:"memo_limit_in_bytes,omitempty"` + // Maximum size of the payback address. + PaybackAddressLimitInBytes uint32 `protobuf:"varint,9,opt,name=payback_address_limit_in_bytes,json=paybackAddressLimitInBytes,proto3" json:"payback_address_limit_in_bytes,omitempty"` + // Maximum size of the SEDA payload. + SEDAPayloadLimitInBytes uint32 `protobuf:"varint,10,opt,name=s_e_d_a_payload_limit_in_bytes,json=sEDAPayloadLimitInBytes,proto3" json:"s_e_d_a_payload_limit_in_bytes,omitempty"` +} + +func (m *DataRequestConfig) Reset() { *m = DataRequestConfig{} } +func (m *DataRequestConfig) String() string { return proto.CompactTextString(m) } +func (*DataRequestConfig) ProtoMessage() {} +func (*DataRequestConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{4} +} +func (m *DataRequestConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DataRequestConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DataRequestConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DataRequestConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_DataRequestConfig.Merge(m, src) +} +func (m *DataRequestConfig) XXX_Size() int { + return m.Size() +} +func (m *DataRequestConfig) XXX_DiscardUnknown() { + xxx_messageInfo_DataRequestConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_DataRequestConfig proto.InternalMessageInfo + +func (m *DataRequestConfig) GetCommitTimeoutInBlocks() uint32 { + if m != nil { + return m.CommitTimeoutInBlocks + } + return 0 +} + +func (m *DataRequestConfig) GetRevealTimeoutInBlocks() uint32 { + if m != nil { + return m.RevealTimeoutInBlocks + } + return 0 +} + +func (m *DataRequestConfig) GetBackupDelayInBlocks() uint32 { + if m != nil { + return m.BackupDelayInBlocks + } + return 0 +} + +func (m *DataRequestConfig) GetDrRevealSizeLimitInBytes() uint32 { + if m != nil { + return m.DrRevealSizeLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetExecInputLimitInBytes() uint32 { + if m != nil { + return m.ExecInputLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetTallyInputLimitInBytes() uint32 { + if m != nil { + return m.TallyInputLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetConsensusFilterLimitInBytes() uint32 { + if m != nil { + return m.ConsensusFilterLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetMemoLimitInBytes() uint32 { + if m != nil { + return m.MemoLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetPaybackAddressLimitInBytes() uint32 { + if m != nil { + return m.PaybackAddressLimitInBytes + } + return 0 +} + +func (m *DataRequestConfig) GetSEDAPayloadLimitInBytes() uint32 { + if m != nil { + return m.SEDAPayloadLimitInBytes + } + return 0 +} + +// StakingConfig defines staking-related parameters. +type StakingConfig struct { + // MiminumStake is the minimum amount of SEDA tokens required to register as + // an Overlay. + MinimumStake cosmossdk_io_math.Int `protobuf:"bytes,1,opt,name=minimum_stake,json=minimumStake,proto3,customtype=cosmossdk.io/math.Int" json:"minimum_stake"` + // AllowlistEnabled is a flag that indicates whether the allowlist is enabled. + AllowlistEnabled bool `protobuf:"varint,2,opt,name=allowlist_enabled,json=allowlistEnabled,proto3" json:"allowlist_enabled,omitempty"` +} + +func (m *StakingConfig) Reset() { *m = StakingConfig{} } +func (m *StakingConfig) String() string { return proto.CompactTextString(m) } +func (*StakingConfig) ProtoMessage() {} +func (*StakingConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{5} +} +func (m *StakingConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *StakingConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_StakingConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *StakingConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_StakingConfig.Merge(m, src) +} +func (m *StakingConfig) XXX_Size() int { + return m.Size() +} +func (m *StakingConfig) XXX_DiscardUnknown() { + xxx_messageInfo_StakingConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_StakingConfig proto.InternalMessageInfo + +func (m *StakingConfig) GetAllowlistEnabled() bool { + if m != nil { + return m.AllowlistEnabled + } + return false +} + +// TallyConfig definfes tally-related parameters. +type TallyConfig struct { + // MaxTallyGasLimit is the maximum gas limit for a tally request. + MaxTallyGasLimit uint64 `protobuf:"varint,1,opt,name=max_tally_gas_limit,json=maxTallyGasLimit,proto3" json:"max_tally_gas_limit,omitempty"` + // FilterGasCostNone is the gas cost for a filter type none. + FilterGasCostNone uint64 `protobuf:"varint,2,opt,name=filter_gas_cost_none,json=filterGasCostNone,proto3" json:"filter_gas_cost_none,omitempty"` + // FilterGasCostMultiplierMode is the gas cost multiplier for a filter type + // mode. + FilterGasCostMultiplierMode uint64 `protobuf:"varint,3,opt,name=filter_gas_cost_multiplier_mode,json=filterGasCostMultiplierMode,proto3" json:"filter_gas_cost_multiplier_mode,omitempty"` + // FilterGasCostMAD is the gas cost multiplier for a filter type + // Median Absolute Deviation. + FilterGasCostMultiplierMAD uint64 `protobuf:"varint,4,opt,name=filter_gas_cost_multiplier_m_a_d,json=filterGasCostMultiplierMAD,proto3" json:"filter_gas_cost_multiplier_m_a_d,omitempty"` + // GasCostBase is the base gas cost for a data request. + GasCostBase uint64 `protobuf:"varint,5,opt,name=gas_cost_base,json=gasCostBase,proto3" json:"gas_cost_base,omitempty"` + // GasCostFallback is the gas cost incurred for data request execution when + // even basic consensus has not been reached. + ExecutionGasCostFallback uint64 `protobuf:"varint,6,opt,name=execution_gas_cost_fallback,json=executionGasCostFallback,proto3" json:"execution_gas_cost_fallback,omitempty"` + // BurnRatio is the ratio of the gas cost to be burned in case of reduced + // payout scenarios. + BurnRatio cosmossdk_io_math.LegacyDec `protobuf:"bytes,7,opt,name=burn_ratio,json=burnRatio,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"burn_ratio"` + // MaxResultSize is the maximum size of the result of a data request in bytes. + MaxResultSize uint32 `protobuf:"varint,8,opt,name=max_result_size,json=maxResultSize,proto3" json:"max_result_size,omitempty"` + // MaxTalliesPerBlock specifies the maximum number of tallies per block. + MaxTalliesPerBlock uint32 `protobuf:"varint,9,opt,name=max_tallies_per_block,json=maxTalliesPerBlock,proto3" json:"max_tallies_per_block,omitempty"` +} + +func (m *TallyConfig) Reset() { *m = TallyConfig{} } +func (m *TallyConfig) String() string { return proto.CompactTextString(m) } +func (*TallyConfig) ProtoMessage() {} +func (*TallyConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_0152bc97eaf51aad, []int{6} +} +func (m *TallyConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *TallyConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_TallyConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *TallyConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_TallyConfig.Merge(m, src) +} +func (m *TallyConfig) XXX_Size() int { + return m.Size() +} +func (m *TallyConfig) XXX_DiscardUnknown() { + xxx_messageInfo_TallyConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_TallyConfig proto.InternalMessageInfo + +func (m *TallyConfig) GetMaxTallyGasLimit() uint64 { + if m != nil { + return m.MaxTallyGasLimit + } + return 0 +} + +func (m *TallyConfig) GetFilterGasCostNone() uint64 { + if m != nil { + return m.FilterGasCostNone + } + return 0 +} + +func (m *TallyConfig) GetFilterGasCostMultiplierMode() uint64 { + if m != nil { + return m.FilterGasCostMultiplierMode + } + return 0 +} + +func (m *TallyConfig) GetFilterGasCostMultiplierMAD() uint64 { + if m != nil { + return m.FilterGasCostMultiplierMAD + } + return 0 +} + +func (m *TallyConfig) GetGasCostBase() uint64 { + if m != nil { + return m.GasCostBase + } + return 0 +} + +func (m *TallyConfig) GetExecutionGasCostFallback() uint64 { + if m != nil { + return m.ExecutionGasCostFallback + } + return 0 +} + +func (m *TallyConfig) GetMaxResultSize() uint32 { + if m != nil { + return m.MaxResultSize + } + return 0 +} + +func (m *TallyConfig) GetMaxTalliesPerBlock() uint32 { + if m != nil { + return m.MaxTalliesPerBlock + } + return 0 +} + +func init() { + proto.RegisterEnum("sedachain.core.v1.DataRequestStatus", DataRequestStatus_name, DataRequestStatus_value) + proto.RegisterType((*Staker)(nil), "sedachain.core.v1.Staker") + proto.RegisterType((*DataRequest)(nil), "sedachain.core.v1.DataRequest") + proto.RegisterMapType((map[string][]byte)(nil), "sedachain.core.v1.DataRequest.CommitsEntry") + proto.RegisterMapType((map[string]bool)(nil), "sedachain.core.v1.DataRequest.RevealsEntry") + proto.RegisterType((*RevealBody)(nil), "sedachain.core.v1.RevealBody") + proto.RegisterType((*Params)(nil), "sedachain.core.v1.Params") + proto.RegisterType((*DataRequestConfig)(nil), "sedachain.core.v1.DataRequestConfig") + proto.RegisterType((*StakingConfig)(nil), "sedachain.core.v1.StakingConfig") + proto.RegisterType((*TallyConfig)(nil), "sedachain.core.v1.TallyConfig") +} + +func init() { proto.RegisterFile("sedachain/core/v1/core.proto", fileDescriptor_0152bc97eaf51aad) } + +var fileDescriptor_0152bc97eaf51aad = []byte{ + // 1617 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x57, 0x4f, 0x6f, 0x1b, 0xc7, + 0x15, 0xd7, 0x8a, 0x34, 0x25, 0x3e, 0xfe, 0x11, 0x39, 0x92, 0x9c, 0xb5, 0x14, 0x93, 0x34, 0xe3, + 0xb6, 0x6a, 0x0c, 0x93, 0x75, 0x02, 0xb4, 0x81, 0x9b, 0xc2, 0x20, 0x45, 0x5a, 0x21, 0x22, 0xb9, + 0xea, 0x92, 0x6a, 0x51, 0x5f, 0x06, 0xc3, 0xdd, 0x31, 0x35, 0xd0, 0xee, 0x0e, 0xbb, 0xb3, 0x2b, + 0x8b, 0xf9, 0x04, 0x3d, 0x15, 0x05, 0xfa, 0x11, 0x7a, 0x68, 0x81, 0x5e, 0x7a, 0xe8, 0x87, 0xc8, + 0x31, 0xe8, 0xa1, 0x28, 0x7a, 0x10, 0x0a, 0xfb, 0x50, 0x40, 0xfd, 0x0a, 0x05, 0x5a, 0xcc, 0x1f, + 0x52, 0x24, 0xad, 0x26, 0xb1, 0x2f, 0x12, 0xe7, 0xf7, 0xde, 0xef, 0x37, 0x33, 0xef, 0xcd, 0xbc, + 0x37, 0x0b, 0xef, 0x0b, 0xea, 0x11, 0xf7, 0x94, 0xb0, 0xb0, 0xe9, 0xf2, 0x88, 0x36, 0xcf, 0x1f, + 0xa9, 0xff, 0x8d, 0x71, 0xc4, 0x63, 0x8e, 0xca, 0x33, 0x6b, 0x43, 0xa1, 0xe7, 0x8f, 0x76, 0xb6, + 0x46, 0x7c, 0xc4, 0x95, 0xb5, 0x29, 0x7f, 0x69, 0xc7, 0x9d, 0x32, 0x09, 0x58, 0xc8, 0x9b, 0xea, + 0xaf, 0x81, 0xee, 0xb8, 0x5c, 0x04, 0x5c, 0x60, 0xed, 0xab, 0x07, 0xda, 0x54, 0xff, 0xaf, 0x05, + 0x99, 0x7e, 0x4c, 0xce, 0x68, 0x84, 0xee, 0x02, 0x8c, 0x93, 0xa1, 0xcf, 0x5c, 0x7c, 0x46, 0x27, + 0xb6, 0x55, 0xb3, 0xf6, 0xb2, 0x4e, 0x56, 0x23, 0x9f, 0xd3, 0x09, 0x42, 0x90, 0x0e, 0x68, 0xc0, + 0xed, 0x55, 0x65, 0x50, 0xbf, 0xd1, 0x3e, 0x64, 0x84, 0x24, 0x7b, 0x76, 0x4a, 0xa2, 0xed, 0x07, + 0x5f, 0x5e, 0x56, 0x57, 0xfe, 0x71, 0x59, 0xdd, 0xd6, 0x73, 0x08, 0xef, 0xac, 0xc1, 0x78, 0x33, + 0x20, 0xf1, 0x69, 0xa3, 0x17, 0xc6, 0x7f, 0xfd, 0xcb, 0x43, 0x30, 0x93, 0xf7, 0xc2, 0xd8, 0x31, + 0x54, 0xf4, 0x1c, 0xd0, 0x98, 0x86, 0x1e, 0x0b, 0x47, 0xf8, 0x25, 0x8b, 0x4f, 0xbd, 0x88, 0xbc, + 0x24, 0xbe, 0x9d, 0x7e, 0x7b, 0xc1, 0xb2, 0x91, 0xf9, 0xc5, 0x4c, 0x05, 0xdd, 0x83, 0xbc, 0xa0, + 0xbf, 0x4a, 0x68, 0xe8, 0x52, 0x1c, 0x26, 0x81, 0x7d, 0xab, 0x66, 0xed, 0xa5, 0x9d, 0xdc, 0x14, + 0x7b, 0x96, 0x04, 0xf5, 0x3f, 0x65, 0x21, 0xd7, 0x21, 0x31, 0x71, 0x24, 0x26, 0x62, 0xf4, 0x1e, + 0xa4, 0x18, 0xf6, 0xf4, 0xfe, 0xdb, 0x99, 0xab, 0xcb, 0xea, 0x2a, 0xf3, 0x9c, 0x55, 0xd6, 0x41, + 0x36, 0xac, 0x9d, 0xd3, 0x48, 0x30, 0x1e, 0x9a, 0x18, 0x4c, 0x87, 0xe8, 0x53, 0x28, 0xd1, 0x0b, + 0xea, 0xca, 0xf8, 0x8e, 0x22, 0x12, 0x60, 0xc9, 0xd7, 0x01, 0xd9, 0xbc, 0xba, 0xac, 0x6e, 0x2c, + 0xda, 0x3c, 0xa7, 0x20, 0x81, 0x63, 0x3d, 0xee, 0x75, 0x50, 0x15, 0x72, 0xca, 0x83, 0x85, 0xe3, + 0x24, 0x16, 0x6a, 0xe3, 0x79, 0x07, 0x24, 0xd4, 0x53, 0x08, 0xba, 0x0f, 0x45, 0xe5, 0x30, 0x22, + 0x02, 0xfb, 0x2c, 0x60, 0xb1, 0xd9, 0x46, 0x5e, 0xa2, 0x07, 0x44, 0x1c, 0x4a, 0x0c, 0x3d, 0x81, + 0x72, 0x4c, 0x7c, 0x7f, 0xb2, 0xb0, 0x8a, 0x8c, 0x5a, 0xc5, 0xd6, 0xd5, 0x65, 0xb5, 0xb4, 0x64, + 0xf4, 0x9c, 0xa2, 0x42, 0xae, 0xd7, 0x71, 0x0f, 0xf2, 0xda, 0xc7, 0x2c, 0x64, 0x4d, 0x2d, 0x24, + 0xa7, 0x30, 0xb3, 0x92, 0xef, 0xc2, 0x86, 0x76, 0xb9, 0x5e, 0xca, 0xba, 0x5a, 0x4a, 0x41, 0xc1, + 0xb3, 0xb5, 0x3c, 0x04, 0x14, 0xd1, 0xb1, 0xcf, 0x5c, 0x12, 0x33, 0x1e, 0xe2, 0x17, 0xc4, 0x8d, + 0x79, 0x64, 0x67, 0x6b, 0xd6, 0x5e, 0xc1, 0x29, 0xcf, 0x59, 0x9e, 0x2a, 0x03, 0xfa, 0x3e, 0x94, + 0x5c, 0x1e, 0x0a, 0x1a, 0x8a, 0x44, 0xe0, 0x17, 0xcc, 0x8f, 0x69, 0x64, 0x83, 0x9a, 0x7d, 0x63, + 0x86, 0x3f, 0x55, 0x30, 0x3a, 0x82, 0xac, 0x9c, 0x7b, 0x1c, 0x31, 0x97, 0xda, 0x39, 0xb5, 0xbb, + 0x1f, 0xbc, 0xc5, 0x19, 0xf9, 0xe3, 0xbf, 0xfe, 0xfc, 0xa1, 0xe5, 0xac, 0x8f, 0x88, 0x38, 0x96, + 0x0a, 0xb3, 0x43, 0x9d, 0x57, 0xb3, 0xe9, 0x43, 0xfd, 0x3d, 0xd8, 0x18, 0x93, 0xc9, 0x90, 0xb8, + 0x67, 0x98, 0x78, 0x5e, 0x44, 0x85, 0xb0, 0x0b, 0xca, 0x5c, 0x34, 0x70, 0x4b, 0xa3, 0xe8, 0x3e, + 0x6c, 0x08, 0x4c, 0xb1, 0x87, 0x09, 0x1e, 0x93, 0x89, 0xcf, 0x89, 0x67, 0x17, 0x75, 0xcc, 0x44, + 0xb7, 0xd3, 0x3a, 0xd6, 0x10, 0xfa, 0x00, 0x0a, 0x63, 0x2e, 0x62, 0xea, 0xe1, 0x53, 0xca, 0x46, + 0xa7, 0xb1, 0xbd, 0x51, 0xb3, 0xf6, 0x52, 0x4e, 0x5e, 0x83, 0x9f, 0x29, 0x0c, 0x3d, 0x87, 0x92, + 0x71, 0xba, 0xde, 0x5d, 0xe9, 0x1d, 0x77, 0x57, 0xd4, 0x4a, 0x07, 0xd3, 0x3d, 0x76, 0x61, 0xcd, + 0xe5, 0x41, 0xc0, 0x62, 0x61, 0x97, 0x6b, 0xa9, 0xbd, 0xdc, 0x47, 0x0f, 0x1a, 0x6f, 0xd4, 0x92, + 0xc6, 0xdc, 0x0d, 0x68, 0xec, 0x6b, 0xef, 0x6e, 0x18, 0x47, 0x13, 0x67, 0xca, 0x95, 0x32, 0x11, + 0x3d, 0xa7, 0xc4, 0x17, 0x36, 0xfa, 0x56, 0x32, 0x8e, 0xf6, 0x36, 0x32, 0x86, 0x8b, 0x6e, 0x43, + 0x46, 0xad, 0x2f, 0xb2, 0x37, 0xd5, 0x25, 0x32, 0x23, 0xf4, 0x19, 0x64, 0xa8, 0x70, 0x23, 0xfe, + 0xd2, 0xde, 0x7a, 0xc7, 0x7d, 0x1b, 0x3e, 0xfa, 0x0e, 0x14, 0x63, 0x16, 0x50, 0x9e, 0xc4, 0xd3, + 0x88, 0x6f, 0xab, 0x88, 0x17, 0x0c, 0x6a, 0x42, 0xfe, 0xa9, 0xaa, 0x5d, 0x71, 0x22, 0xec, 0xdb, + 0x35, 0x6b, 0xaf, 0xf8, 0xd1, 0xfd, 0xaf, 0xdf, 0x4e, 0x5f, 0xf9, 0x3a, 0x86, 0xb3, 0xf3, 0x18, + 0xf2, 0xf3, 0x61, 0x42, 0x25, 0x48, 0x5d, 0x57, 0x4d, 0xf9, 0x13, 0x6d, 0xc1, 0xad, 0x73, 0xe2, + 0x27, 0x54, 0x15, 0x8b, 0xbc, 0xa3, 0x07, 0x8f, 0x57, 0x3f, 0xb1, 0x24, 0x77, 0x3e, 0x36, 0xdf, + 0xc4, 0x5d, 0x9f, 0xe3, 0xd6, 0xff, 0x66, 0x01, 0x68, 0x72, 0x9b, 0x7b, 0x13, 0xb4, 0x09, 0xb7, + 0xbc, 0x08, 0x33, 0x53, 0xae, 0x9c, 0xb4, 0x17, 0xf5, 0x3c, 0x79, 0x4b, 0xbd, 0x08, 0x0f, 0x7d, + 0xee, 0x9e, 0x4d, 0x23, 0xb0, 0xaa, 0x6f, 0xa9, 0x17, 0xb5, 0x25, 0x6a, 0x22, 0xb0, 0x0b, 0x59, + 0x7a, 0xc1, 0x62, 0xec, 0x72, 0x8f, 0xaa, 0x7a, 0x55, 0x70, 0xd6, 0x25, 0xb0, 0xcf, 0x3d, 0x8a, + 0xee, 0x80, 0xbc, 0x25, 0x38, 0x11, 0xd4, 0x53, 0x25, 0x29, 0xed, 0xac, 0x8d, 0x88, 0x38, 0x11, + 0xd4, 0x93, 0x29, 0xd4, 0xd9, 0x54, 0x75, 0x28, 0xef, 0x98, 0x11, 0xfa, 0x31, 0x14, 0xc7, 0x11, + 0xbf, 0x98, 0xe0, 0x71, 0x32, 0x94, 0x3d, 0x44, 0xd8, 0x99, 0x5a, 0x6a, 0x2f, 0xdb, 0xde, 0xbe, + 0xba, 0xac, 0x96, 0x67, 0x16, 0xd3, 0x60, 0x84, 0x93, 0x57, 0xd0, 0x71, 0x32, 0xfc, 0x9c, 0x4e, + 0x44, 0xfd, 0x3f, 0x16, 0x64, 0x8e, 0x49, 0x44, 0x02, 0x81, 0x9e, 0xc3, 0xa6, 0x47, 0x62, 0x82, + 0x23, 0x1d, 0x79, 0xec, 0xf2, 0xf0, 0x05, 0x1b, 0xa9, 0x2d, 0xe6, 0xbe, 0x29, 0x4d, 0xfb, 0xca, + 0xb7, 0x9d, 0x96, 0xa7, 0xc7, 0x29, 0x7b, 0xcb, 0x06, 0x74, 0x04, 0x45, 0xd9, 0x76, 0x64, 0xb3, + 0x31, 0xb2, 0xab, 0x4a, 0xb6, 0x76, 0x83, 0x6c, 0x5f, 0x3b, 0x2e, 0x48, 0x16, 0xc4, 0x3c, 0x88, + 0x0e, 0xa6, 0x35, 0xd3, 0x88, 0xa5, 0x94, 0x58, 0xe5, 0x06, 0xb1, 0x81, 0x74, 0x5b, 0x90, 0xd2, + 0x95, 0x55, 0x43, 0xf5, 0x7f, 0xa7, 0xa1, 0xfc, 0xc6, 0x36, 0xd0, 0x8f, 0xc0, 0xd6, 0xd7, 0x0f, + 0x4f, 0x4f, 0x34, 0x0b, 0x75, 0x62, 0x85, 0x0a, 0x47, 0xc1, 0xd9, 0xd6, 0xf6, 0x81, 0x36, 0xf7, + 0x42, 0x95, 0x5f, 0x21, 0x89, 0x3a, 0x29, 0x37, 0x10, 0x57, 0x35, 0x51, 0xdb, 0x97, 0x89, 0x1f, + 0xc3, 0x6d, 0x59, 0xe2, 0x92, 0x31, 0xf6, 0xa8, 0x4f, 0x26, 0x73, 0x34, 0x7d, 0x40, 0x36, 0xb5, + 0xb5, 0x23, 0x8d, 0x33, 0xd2, 0x13, 0xb8, 0xeb, 0x45, 0xd8, 0x4c, 0x28, 0xd8, 0x17, 0x54, 0xf7, + 0x06, 0x45, 0x9e, 0xc4, 0x54, 0xf7, 0xb4, 0x82, 0x63, 0x7b, 0x91, 0x3e, 0xba, 0x7d, 0xf6, 0x05, + 0x55, 0x8d, 0xa2, 0x17, 0xb6, 0xa5, 0x1d, 0x7d, 0x02, 0x77, 0xae, 0x5b, 0xe0, 0x32, 0xf9, 0x96, + 0x5e, 0xef, 0xac, 0x21, 0x2e, 0x30, 0x1f, 0xc3, 0xce, 0x5c, 0xd3, 0x5a, 0xa6, 0x66, 0x14, 0xf5, + 0xf6, 0x75, 0x0b, 0x5b, 0xe0, 0x76, 0xa0, 0xba, 0xdc, 0x76, 0x96, 0x05, 0xd6, 0x94, 0xc0, 0xee, + 0x52, 0x17, 0x5a, 0x50, 0x79, 0x08, 0x9b, 0xb2, 0x6d, 0x2c, 0x33, 0xd7, 0x15, 0xb3, 0x24, 0x4d, + 0x0b, 0xee, 0x6d, 0xa8, 0x2c, 0x75, 0x97, 0x65, 0xa6, 0x6e, 0x93, 0x3b, 0x8b, 0xcd, 0x66, 0x41, + 0xe3, 0x09, 0x54, 0x96, 0x1a, 0xcf, 0xb2, 0x06, 0x28, 0x8d, 0xf7, 0xe6, 0xfa, 0xd0, 0xbc, 0x40, + 0xfd, 0x77, 0x16, 0x14, 0x16, 0x4e, 0x37, 0x3a, 0x81, 0x42, 0xc0, 0x42, 0x16, 0x24, 0x01, 0x56, + 0xcf, 0x32, 0xf3, 0xfe, 0x79, 0xfb, 0x2a, 0x9c, 0x37, 0x32, 0xea, 0x51, 0x89, 0x1e, 0x40, 0x99, + 0xf8, 0x3e, 0x7f, 0xe9, 0x33, 0x11, 0x63, 0x1a, 0x92, 0xa1, 0x4f, 0x3d, 0x53, 0xd4, 0x4a, 0x33, + 0x43, 0x57, 0xe3, 0xf5, 0xdf, 0xa4, 0x21, 0x37, 0x77, 0x4d, 0x54, 0x64, 0xc9, 0x05, 0x5e, 0x7e, + 0x71, 0x58, 0xaa, 0x1a, 0x95, 0x02, 0x72, 0x31, 0x58, 0x78, 0x74, 0x34, 0x61, 0xcb, 0x24, 0x51, + 0xfa, 0xba, 0x5c, 0xc4, 0x38, 0xe4, 0x21, 0x35, 0xb5, 0xaf, 0xac, 0x6d, 0x07, 0x44, 0xec, 0x73, + 0x11, 0x3f, 0xe3, 0x21, 0x95, 0xf9, 0x5f, 0x26, 0x04, 0x89, 0x1f, 0xb3, 0xb1, 0xcf, 0x68, 0x84, + 0x83, 0x69, 0x55, 0x4c, 0x3b, 0xbb, 0x0b, 0xdc, 0xa3, 0x99, 0xcf, 0x91, 0x2c, 0x94, 0x1d, 0xa8, + 0x7d, 0x9d, 0x0a, 0x26, 0x78, 0x5a, 0x40, 0x77, 0xfe, 0x9f, 0x4c, 0xab, 0x83, 0xea, 0x50, 0x98, + 0xd1, 0x87, 0x44, 0xd0, 0xe9, 0x4b, 0x75, 0xa4, 0x9d, 0xdb, 0x44, 0x50, 0xf4, 0x13, 0xd8, 0x95, + 0x97, 0x20, 0x51, 0x6f, 0xaa, 0x99, 0xf7, 0x0b, 0xe2, 0xfb, 0xf2, 0xa0, 0xa8, 0xc3, 0x9e, 0x76, + 0xec, 0x99, 0x8b, 0x99, 0xe7, 0xa9, 0xb1, 0xa3, 0x13, 0x80, 0x61, 0x12, 0x85, 0x38, 0x92, 0x4f, + 0x2f, 0x75, 0xb2, 0xb3, 0xed, 0x1f, 0x9a, 0xfc, 0xee, 0xbe, 0x99, 0xdf, 0x43, 0x3a, 0x22, 0xee, + 0xa4, 0x43, 0xdd, 0xb9, 0x2c, 0x77, 0xa8, 0xab, 0xb3, 0x9c, 0x95, 0x4a, 0x8e, 0x14, 0x92, 0xdd, + 0x46, 0x66, 0x29, 0xa2, 0x22, 0xf1, 0x63, 0x75, 0xfb, 0xcd, 0xd9, 0x2f, 0x04, 0xe4, 0xc2, 0x51, + 0xa8, 0xbc, 0xef, 0xe8, 0x11, 0x6c, 0x4f, 0xb3, 0xc9, 0xa8, 0xc0, 0x63, 0x6a, 0x5a, 0x94, 0x39, + 0xef, 0xc8, 0xe4, 0x93, 0x51, 0x71, 0x4c, 0x75, 0x9b, 0xfa, 0xf0, 0x0f, 0xd6, 0x42, 0x51, 0xd4, + 0x2d, 0x18, 0x7d, 0x00, 0xd5, 0x4e, 0x6b, 0xd0, 0xc2, 0x4e, 0xf7, 0x67, 0x27, 0xdd, 0xfe, 0x00, + 0xf7, 0x07, 0xad, 0xc1, 0x49, 0x1f, 0x9f, 0x3c, 0xeb, 0x1f, 0x77, 0xf7, 0x7b, 0x4f, 0x7b, 0xdd, + 0x4e, 0x69, 0x05, 0xd5, 0xa1, 0x72, 0x93, 0xd3, 0xfe, 0x4f, 0x8f, 0x8e, 0x7a, 0x83, 0x41, 0xef, + 0xd9, 0x41, 0xc9, 0x42, 0xf7, 0xe0, 0xee, 0x4d, 0x3e, 0x4e, 0xf7, 0xe7, 0xdd, 0xd6, 0xa1, 0x74, + 0x59, 0x45, 0x35, 0x78, 0xff, 0x26, 0x97, 0x41, 0xeb, 0xf0, 0xf0, 0x97, 0xd2, 0x23, 0xb5, 0x93, + 0xfe, 0xf5, 0xef, 0x2b, 0x2b, 0xed, 0xde, 0x97, 0xaf, 0x2a, 0xd6, 0x57, 0xaf, 0x2a, 0xd6, 0x3f, + 0x5f, 0x55, 0xac, 0xdf, 0xbe, 0xae, 0xac, 0x7c, 0xf5, 0xba, 0xb2, 0xf2, 0xf7, 0xd7, 0x95, 0x95, + 0xe7, 0xcd, 0x11, 0x8b, 0x4f, 0x93, 0x61, 0xc3, 0xe5, 0x41, 0x53, 0x76, 0x05, 0xf5, 0xd9, 0xe5, + 0x72, 0x5f, 0x0d, 0x1e, 0xea, 0xcf, 0xbd, 0x0b, 0xfd, 0xc1, 0x17, 0x4f, 0xc6, 0x54, 0x0c, 0x33, + 0xca, 0xe3, 0xe3, 0xff, 0x05, 0x00, 0x00, 0xff, 0xff, 0xac, 0xcf, 0x38, 0x82, 0x0f, 0x0e, 0x00, + 0x00, +} + +func (m *Staker) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Staker) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Staker) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SequenceNum != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.SequenceNum)) + i-- + dAtA[i] = 0x28 + } + { + size := m.PendingWithdrawal.Size() + i -= size + if _, err := m.PendingWithdrawal.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + { + size := m.Staked.Size() + i -= size + if _, err := m.Staked.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintCore(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x12 + } + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintCore(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *DataRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DataRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DataRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Status != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.Status)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xb0 + } + if m.TimeoutHeight != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.TimeoutHeight)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa8 + } + { + size := m.Escrow.Size() + i -= size + if _, err := m.Escrow.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0xa2 + if len(m.Poster) > 0 { + i -= len(m.Poster) + copy(dAtA[i:], m.Poster) + i = encodeVarintCore(dAtA, i, uint64(len(m.Poster))) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x9a + } + if len(m.Reveals) > 0 { + for k := range m.Reveals { + v := m.Reveals[k] + baseI := i + i-- + if v { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + i -= len(k) + copy(dAtA[i:], k) + i = encodeVarintCore(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = encodeVarintCore(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x92 + } + } + if len(m.Commits) > 0 { + for k := range m.Commits { + v := m.Commits[k] + baseI := i + if len(v) > 0 { + i -= len(v) + copy(dAtA[i:], v) + i = encodeVarintCore(dAtA, i, uint64(len(v))) + i-- + dAtA[i] = 0x12 + } + i -= len(k) + copy(dAtA[i:], k) + i = encodeVarintCore(dAtA, i, uint64(len(k))) + i-- + dAtA[i] = 0xa + i = encodeVarintCore(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x8a + } + } + { + size := m.PostedGasPrice.Size() + i -= size + if _, err := m.PostedGasPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 + if m.PostedHeight != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.PostedHeight)) + i-- + dAtA[i] = 0x78 + } + if len(m.SEDAPayload) > 0 { + i -= len(m.SEDAPayload) + copy(dAtA[i:], m.SEDAPayload) + i = encodeVarintCore(dAtA, i, uint64(len(m.SEDAPayload))) + i-- + dAtA[i] = 0x72 + } + if len(m.PaybackAddress) > 0 { + i -= len(m.PaybackAddress) + copy(dAtA[i:], m.PaybackAddress) + i = encodeVarintCore(dAtA, i, uint64(len(m.PaybackAddress))) + i-- + dAtA[i] = 0x6a + } + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintCore(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x62 + } + { + size := m.GasPrice.Size() + i -= size + if _, err := m.GasPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + if len(m.ConsensusFilter) > 0 { + i -= len(m.ConsensusFilter) + copy(dAtA[i:], m.ConsensusFilter) + i = encodeVarintCore(dAtA, i, uint64(len(m.ConsensusFilter))) + i-- + dAtA[i] = 0x52 + } + if m.ReplicationFactor != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ReplicationFactor)) + i-- + dAtA[i] = 0x48 + } + if m.TallyGasLimit != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.TallyGasLimit)) + i-- + dAtA[i] = 0x40 + } + if len(m.TallyInputs) > 0 { + i -= len(m.TallyInputs) + copy(dAtA[i:], m.TallyInputs) + i = encodeVarintCore(dAtA, i, uint64(len(m.TallyInputs))) + i-- + dAtA[i] = 0x3a + } + if len(m.TallyProgramID) > 0 { + i -= len(m.TallyProgramID) + copy(dAtA[i:], m.TallyProgramID) + i = encodeVarintCore(dAtA, i, uint64(len(m.TallyProgramID))) + i-- + dAtA[i] = 0x32 + } + if m.ExecGasLimit != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ExecGasLimit)) + i-- + dAtA[i] = 0x28 + } + if len(m.ExecInputs) > 0 { + i -= len(m.ExecInputs) + copy(dAtA[i:], m.ExecInputs) + i = encodeVarintCore(dAtA, i, uint64(len(m.ExecInputs))) + i-- + dAtA[i] = 0x22 + } + if len(m.ExecProgramID) > 0 { + i -= len(m.ExecProgramID) + copy(dAtA[i:], m.ExecProgramID) + i = encodeVarintCore(dAtA, i, uint64(len(m.ExecProgramID))) + i-- + dAtA[i] = 0x1a + } + if len(m.Version) > 0 { + i -= len(m.Version) + copy(dAtA[i:], m.Version) + i = encodeVarintCore(dAtA, i, uint64(len(m.Version))) + i-- + dAtA[i] = 0x12 + } + if len(m.ID) > 0 { + i -= len(m.ID) + copy(dAtA[i:], m.ID) + i = encodeVarintCore(dAtA, i, uint64(len(m.ID))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *RevealBody) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *RevealBody) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *RevealBody) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ProxyPubKeys) > 0 { + for iNdEx := len(m.ProxyPubKeys) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.ProxyPubKeys[iNdEx]) + copy(dAtA[i:], m.ProxyPubKeys[iNdEx]) + i = encodeVarintCore(dAtA, i, uint64(len(m.ProxyPubKeys[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if len(m.Reveal) > 0 { + i -= len(m.Reveal) + copy(dAtA[i:], m.Reveal) + i = encodeVarintCore(dAtA, i, uint64(len(m.Reveal))) + i-- + dAtA[i] = 0x2a + } + if m.GasUsed != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.GasUsed)) + i-- + dAtA[i] = 0x20 + } + if m.ExitCode != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ExitCode)) + i-- + dAtA[i] = 0x18 + } + if m.DrBlockHeight != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.DrBlockHeight)) + i-- + dAtA[i] = 0x10 + } + if len(m.DrId) > 0 { + i -= len(m.DrId) + copy(dAtA[i:], m.DrId) + i = encodeVarintCore(dAtA, i, uint64(len(m.DrId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.TallyConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.StakingConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.DataRequestConfig.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *DataRequestConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DataRequestConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DataRequestConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SEDAPayloadLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.SEDAPayloadLimitInBytes)) + i-- + dAtA[i] = 0x50 + } + if m.PaybackAddressLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.PaybackAddressLimitInBytes)) + i-- + dAtA[i] = 0x48 + } + if m.MemoLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.MemoLimitInBytes)) + i-- + dAtA[i] = 0x40 + } + if m.ConsensusFilterLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ConsensusFilterLimitInBytes)) + i-- + dAtA[i] = 0x38 + } + if m.TallyInputLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.TallyInputLimitInBytes)) + i-- + dAtA[i] = 0x30 + } + if m.ExecInputLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ExecInputLimitInBytes)) + i-- + dAtA[i] = 0x28 + } + if m.DrRevealSizeLimitInBytes != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.DrRevealSizeLimitInBytes)) + i-- + dAtA[i] = 0x20 + } + if m.BackupDelayInBlocks != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.BackupDelayInBlocks)) + i-- + dAtA[i] = 0x18 + } + if m.RevealTimeoutInBlocks != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.RevealTimeoutInBlocks)) + i-- + dAtA[i] = 0x10 + } + if m.CommitTimeoutInBlocks != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.CommitTimeoutInBlocks)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func (m *StakingConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *StakingConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *StakingConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.AllowlistEnabled { + i-- + if m.AllowlistEnabled { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x10 + } + { + size := m.MinimumStake.Size() + i -= size + if _, err := m.MinimumStake.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *TallyConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *TallyConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *TallyConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MaxTalliesPerBlock != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.MaxTalliesPerBlock)) + i-- + dAtA[i] = 0x48 + } + if m.MaxResultSize != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.MaxResultSize)) + i-- + dAtA[i] = 0x40 + } + { + size := m.BurnRatio.Size() + i -= size + if _, err := m.BurnRatio.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintCore(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x3a + if m.ExecutionGasCostFallback != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.ExecutionGasCostFallback)) + i-- + dAtA[i] = 0x30 + } + if m.GasCostBase != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.GasCostBase)) + i-- + dAtA[i] = 0x28 + } + if m.FilterGasCostMultiplierMAD != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.FilterGasCostMultiplierMAD)) + i-- + dAtA[i] = 0x20 + } + if m.FilterGasCostMultiplierMode != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.FilterGasCostMultiplierMode)) + i-- + dAtA[i] = 0x18 + } + if m.FilterGasCostNone != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.FilterGasCostNone)) + i-- + dAtA[i] = 0x10 + } + if m.MaxTallyGasLimit != 0 { + i = encodeVarintCore(dAtA, i, uint64(m.MaxTallyGasLimit)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintCore(dAtA []byte, offset int, v uint64) int { + offset -= sovCore(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Staker) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = m.Staked.Size() + n += 1 + l + sovCore(uint64(l)) + l = m.PendingWithdrawal.Size() + n += 1 + l + sovCore(uint64(l)) + if m.SequenceNum != 0 { + n += 1 + sovCore(uint64(m.SequenceNum)) + } + return n +} + +func (m *DataRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ID) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.Version) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.ExecProgramID) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.ExecInputs) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + if m.ExecGasLimit != 0 { + n += 1 + sovCore(uint64(m.ExecGasLimit)) + } + l = len(m.TallyProgramID) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.TallyInputs) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + if m.TallyGasLimit != 0 { + n += 1 + sovCore(uint64(m.TallyGasLimit)) + } + if m.ReplicationFactor != 0 { + n += 1 + sovCore(uint64(m.ReplicationFactor)) + } + l = len(m.ConsensusFilter) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = m.GasPrice.Size() + n += 1 + l + sovCore(uint64(l)) + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.PaybackAddress) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + l = len(m.SEDAPayload) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + if m.PostedHeight != 0 { + n += 1 + sovCore(uint64(m.PostedHeight)) + } + l = m.PostedGasPrice.Size() + n += 2 + l + sovCore(uint64(l)) + if len(m.Commits) > 0 { + for k, v := range m.Commits { + _ = k + _ = v + l = 0 + if len(v) > 0 { + l = 1 + len(v) + sovCore(uint64(len(v))) + } + mapEntrySize := 1 + len(k) + sovCore(uint64(len(k))) + l + n += mapEntrySize + 2 + sovCore(uint64(mapEntrySize)) + } + } + if len(m.Reveals) > 0 { + for k, v := range m.Reveals { + _ = k + _ = v + mapEntrySize := 1 + len(k) + sovCore(uint64(len(k))) + 1 + 1 + n += mapEntrySize + 2 + sovCore(uint64(mapEntrySize)) + } + } + l = len(m.Poster) + if l > 0 { + n += 2 + l + sovCore(uint64(l)) + } + l = m.Escrow.Size() + n += 2 + l + sovCore(uint64(l)) + if m.TimeoutHeight != 0 { + n += 2 + sovCore(uint64(m.TimeoutHeight)) + } + if m.Status != 0 { + n += 2 + sovCore(uint64(m.Status)) + } + return n +} + +func (m *RevealBody) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DrId) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + if m.DrBlockHeight != 0 { + n += 1 + sovCore(uint64(m.DrBlockHeight)) + } + if m.ExitCode != 0 { + n += 1 + sovCore(uint64(m.ExitCode)) + } + if m.GasUsed != 0 { + n += 1 + sovCore(uint64(m.GasUsed)) + } + l = len(m.Reveal) + if l > 0 { + n += 1 + l + sovCore(uint64(l)) + } + if len(m.ProxyPubKeys) > 0 { + for _, s := range m.ProxyPubKeys { + l = len(s) + n += 1 + l + sovCore(uint64(l)) + } + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.DataRequestConfig.Size() + n += 1 + l + sovCore(uint64(l)) + l = m.StakingConfig.Size() + n += 1 + l + sovCore(uint64(l)) + l = m.TallyConfig.Size() + n += 1 + l + sovCore(uint64(l)) + return n +} + +func (m *DataRequestConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CommitTimeoutInBlocks != 0 { + n += 1 + sovCore(uint64(m.CommitTimeoutInBlocks)) + } + if m.RevealTimeoutInBlocks != 0 { + n += 1 + sovCore(uint64(m.RevealTimeoutInBlocks)) + } + if m.BackupDelayInBlocks != 0 { + n += 1 + sovCore(uint64(m.BackupDelayInBlocks)) + } + if m.DrRevealSizeLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.DrRevealSizeLimitInBytes)) + } + if m.ExecInputLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.ExecInputLimitInBytes)) + } + if m.TallyInputLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.TallyInputLimitInBytes)) + } + if m.ConsensusFilterLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.ConsensusFilterLimitInBytes)) + } + if m.MemoLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.MemoLimitInBytes)) + } + if m.PaybackAddressLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.PaybackAddressLimitInBytes)) + } + if m.SEDAPayloadLimitInBytes != 0 { + n += 1 + sovCore(uint64(m.SEDAPayloadLimitInBytes)) + } + return n +} + +func (m *StakingConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.MinimumStake.Size() + n += 1 + l + sovCore(uint64(l)) + if m.AllowlistEnabled { + n += 2 + } + return n +} + +func (m *TallyConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.MaxTallyGasLimit != 0 { + n += 1 + sovCore(uint64(m.MaxTallyGasLimit)) + } + if m.FilterGasCostNone != 0 { + n += 1 + sovCore(uint64(m.FilterGasCostNone)) + } + if m.FilterGasCostMultiplierMode != 0 { + n += 1 + sovCore(uint64(m.FilterGasCostMultiplierMode)) + } + if m.FilterGasCostMultiplierMAD != 0 { + n += 1 + sovCore(uint64(m.FilterGasCostMultiplierMAD)) + } + if m.GasCostBase != 0 { + n += 1 + sovCore(uint64(m.GasCostBase)) + } + if m.ExecutionGasCostFallback != 0 { + n += 1 + sovCore(uint64(m.ExecutionGasCostFallback)) + } + l = m.BurnRatio.Size() + n += 1 + l + sovCore(uint64(l)) + if m.MaxResultSize != 0 { + n += 1 + sovCore(uint64(m.MaxResultSize)) + } + if m.MaxTalliesPerBlock != 0 { + n += 1 + sovCore(uint64(m.MaxTalliesPerBlock)) + } + return n +} + +func sovCore(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozCore(x uint64) (n int) { + return sovCore(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Staker) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Staker: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Staker: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Memo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Staked", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Staked.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PendingWithdrawal", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PendingWithdrawal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SequenceNum", wireType) + } + m.SequenceNum = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SequenceNum |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DataRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DataRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DataRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Version = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecProgramID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExecProgramID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecInputs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExecInputs = append(m.ExecInputs[:0], dAtA[iNdEx:postIndex]...) + if m.ExecInputs == nil { + m.ExecInputs = []byte{} + } + iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecGasLimit", wireType) + } + m.ExecGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyProgramID", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TallyProgramID = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyInputs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TallyInputs = append(m.TallyInputs[:0], dAtA[iNdEx:postIndex]...) + if m.TallyInputs == nil { + m.TallyInputs = []byte{} + } + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyGasLimit", wireType) + } + m.TallyGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TallyGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReplicationFactor", wireType) + } + m.ReplicationFactor = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ReplicationFactor |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusFilter", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusFilter = append(m.ConsensusFilter[:0], dAtA[iNdEx:postIndex]...) + if m.ConsensusFilter == nil { + m.ConsensusFilter = []byte{} + } + iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.GasPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Memo = append(m.Memo[:0], dAtA[iNdEx:postIndex]...) + if m.Memo == nil { + m.Memo = []byte{} + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PaybackAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PaybackAddress = append(m.PaybackAddress[:0], dAtA[iNdEx:postIndex]...) + if m.PaybackAddress == nil { + m.PaybackAddress = []byte{} + } + iNdEx = postIndex + case 14: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SEDAPayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SEDAPayload = append(m.SEDAPayload[:0], dAtA[iNdEx:postIndex]...) + if m.SEDAPayload == nil { + m.SEDAPayload = []byte{} + } + iNdEx = postIndex + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PostedHeight", wireType) + } + m.PostedHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PostedHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 16: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PostedGasPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PostedGasPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 17: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commits", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Commits == nil { + m.Commits = make(map[string][]byte) + } + var mapkey string + mapvalue := []byte{} + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthCore + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthCore + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapbyteLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapbyteLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intMapbyteLen := int(mapbyteLen) + if intMapbyteLen < 0 { + return ErrInvalidLengthCore + } + postbytesIndex := iNdEx + intMapbyteLen + if postbytesIndex < 0 { + return ErrInvalidLengthCore + } + if postbytesIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = make([]byte, mapbyteLen) + copy(mapvalue, dAtA[iNdEx:postbytesIndex]) + iNdEx = postbytesIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Commits[mapkey] = mapvalue + iNdEx = postIndex + case 18: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Reveals", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Reveals == nil { + m.Reveals = make(map[string]bool) + } + var mapkey string + var mapvalue bool + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthCore + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthCore + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapvaluetemp int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapvaluetemp |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + mapvalue = bool(mapvaluetemp != 0) + } else { + iNdEx = entryPreIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Reveals[mapkey] = mapvalue + iNdEx = postIndex + case 19: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Poster", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Poster = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 20: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Escrow", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Escrow.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 21: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TimeoutHeight", wireType) + } + m.TimeoutHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TimeoutHeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 22: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + m.Status = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Status |= DataRequestStatus(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *RevealBody) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: RevealBody: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: RevealBody: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DrId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrBlockHeight", wireType) + } + m.DrBlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrBlockHeight |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExitCode", wireType) + } + m.ExitCode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExitCode |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasUsed", wireType) + } + m.GasUsed = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasUsed |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Reveal", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Reveal = append(m.Reveal[:0], dAtA[iNdEx:postIndex]...) + if m.Reveal == nil { + m.Reveal = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProxyPubKeys", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProxyPubKeys = append(m.ProxyPubKeys, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DataRequestConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.DataRequestConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field StakingConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.StakingConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyConfig", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.TallyConfig.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *DataRequestConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DataRequestConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DataRequestConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CommitTimeoutInBlocks", wireType) + } + m.CommitTimeoutInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CommitTimeoutInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RevealTimeoutInBlocks", wireType) + } + m.RevealTimeoutInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RevealTimeoutInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BackupDelayInBlocks", wireType) + } + m.BackupDelayInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BackupDelayInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrRevealSizeLimitInBytes", wireType) + } + m.DrRevealSizeLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrRevealSizeLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecInputLimitInBytes", wireType) + } + m.ExecInputLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecInputLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyInputLimitInBytes", wireType) + } + m.TallyInputLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TallyInputLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusFilterLimitInBytes", wireType) + } + m.ConsensusFilterLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ConsensusFilterLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MemoLimitInBytes", wireType) + } + m.MemoLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MemoLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PaybackAddressLimitInBytes", wireType) + } + m.PaybackAddressLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PaybackAddressLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SEDAPayloadLimitInBytes", wireType) + } + m.SEDAPayloadLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SEDAPayloadLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *StakingConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: StakingConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: StakingConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MinimumStake", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.MinimumStake.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AllowlistEnabled", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.AllowlistEnabled = bool(v != 0) + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *TallyConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: TallyConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: TallyConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxTallyGasLimit", wireType) + } + m.MaxTallyGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxTallyGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostNone", wireType) + } + m.FilterGasCostNone = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FilterGasCostNone |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostMultiplierMode", wireType) + } + m.FilterGasCostMultiplierMode = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FilterGasCostMultiplierMode |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostMultiplierMAD", wireType) + } + m.FilterGasCostMultiplierMAD = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FilterGasCostMultiplierMAD |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field GasCostBase", wireType) + } + m.GasCostBase = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.GasCostBase |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecutionGasCostFallback", wireType) + } + m.ExecutionGasCostFallback = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecutionGasCostFallback |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field BurnRatio", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthCore + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthCore + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.BurnRatio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxResultSize", wireType) + } + m.MaxResultSize = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxResultSize |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxTalliesPerBlock", wireType) + } + m.MaxTalliesPerBlock = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowCore + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxTalliesPerBlock |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipCore(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthCore + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipCore(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCore + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCore + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowCore + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthCore + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupCore + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthCore + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthCore = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowCore = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupCore = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/core/types/data_request.go b/x/core/types/data_request.go new file mode 100644 index 00000000..ee14d72e --- /dev/null +++ b/x/core/types/data_request.go @@ -0,0 +1,61 @@ +package types + +import ( + "encoding/binary" +) + +// DataRequestIndex is a 56-byte index for data requests used to sort them by +// their posted gas prices and heights. +// 0 16 24 56 (byte) +// | posted_gas_price | height | dr_id | +type DataRequestIndex []byte + +func (i DataRequestIndex) DrID() string { + return string(i[24:]) +} + +func (dr DataRequest) Index() DataRequestIndex { + // Treat gasPrice as a 128-bit unsigned integer. + priceBytes := make([]byte, 16) + dr.PostedGasPrice.BigInt().FillBytes(priceBytes) + + heightBytes := make([]byte, 8) + //nolint:gosec // G115: Block height is never negative. + binary.BigEndian.PutUint64(heightBytes, uint64(dr.PostedHeight)) + + drIDBytes := []byte(dr.ID) // TODO or convert hex to bytes? + return append(append(priceBytes, heightBytes...), drIDBytes...) +} + +func (dr *DataRequest) AddCommit(publicKey string, commit []byte) { + if dr.Commits == nil { + dr.Commits = make(map[string][]byte) + } + dr.Commits[publicKey] = commit +} + +func (dr DataRequest) GetCommit(publicKey string) ([]byte, bool) { + if dr.Commits == nil { + return nil, false + } + commit, exists := dr.Commits[publicKey] + return commit, exists +} + +// MarkAsRevealed adds the given public key to the data request's reveals map +// and returns the count of reveals. +func (dr *DataRequest) MarkAsRevealed(publicKey string) int { + if dr.Reveals == nil { + dr.Reveals = make(map[string]bool) + } + dr.Reveals[publicKey] = true + return len(dr.Reveals) +} + +func (dr DataRequest) HasRevealed(publicKey string) bool { + if dr.Reveals == nil { + return false + } + _, exists := dr.Reveals[publicKey] + return exists +} diff --git a/x/core/types/dr_config.pb.go b/x/core/types/dr_config.pb.go new file mode 100644 index 00000000..f71c55fb --- /dev/null +++ b/x/core/types/dr_config.pb.go @@ -0,0 +1,643 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sedachain/core/v1/dr_config.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// DrConfig defines the configuration for data requests +type DrConfig struct { + // Number of blocks after which a data request is timed out while waiting + // for commits. + CommitTimeoutInBlocks uint32 `protobuf:"varint,1,opt,name=commit_timeout_in_blocks,json=commitTimeoutInBlocks,proto3" json:"commit_timeout_in_blocks,omitempty"` + // Number of blocks after which a data request is timed out while waiting + // for reveals. + RevealTimeoutInBlocks uint32 `protobuf:"varint,2,opt,name=reveal_timeout_in_blocks,json=revealTimeoutInBlocks,proto3" json:"reveal_timeout_in_blocks,omitempty"` + // This is the delay before the backup executors are allowed to start + // executing the data request. + BackupDelayInBlocks uint32 `protobuf:"varint,3,opt,name=backup_delay_in_blocks,json=backupDelayInBlocks,proto3" json:"backup_delay_in_blocks,omitempty"` + // The maximum size of all the reveals in a data request. + DrRevealSizeLimitInBytes uint32 `protobuf:"varint,4,opt,name=dr_reveal_size_limit_in_bytes,json=drRevealSizeLimitInBytes,proto3" json:"dr_reveal_size_limit_in_bytes,omitempty"` + // The maximum size of the input for the execution program. + ExecInputLimitInBytes uint32 `protobuf:"varint,5,opt,name=exec_input_limit_in_bytes,json=execInputLimitInBytes,proto3" json:"exec_input_limit_in_bytes,omitempty"` + // The maximum size of the input for the tally program. + TallyInputLimitInBytes uint32 `protobuf:"varint,6,opt,name=tally_input_limit_in_bytes,json=tallyInputLimitInBytes,proto3" json:"tally_input_limit_in_bytes,omitempty"` + // The maximum size of the consensus filter. + ConsensusFilterLimitInBytes uint32 `protobuf:"varint,7,opt,name=consensus_filter_limit_in_bytes,json=consensusFilterLimitInBytes,proto3" json:"consensus_filter_limit_in_bytes,omitempty"` + // The maximum size of the memo. + MemoLimitInBytes uint32 `protobuf:"varint,8,opt,name=memo_limit_in_bytes,json=memoLimitInBytes,proto3" json:"memo_limit_in_bytes,omitempty"` + // The maximum size of the payback address. + PaybackAddressLimitInBytes uint32 `protobuf:"varint,9,opt,name=payback_address_limit_in_bytes,json=paybackAddressLimitInBytes,proto3" json:"payback_address_limit_in_bytes,omitempty"` + // The maximum size of the SEDA payload. + SedaPayloadLimitInBytes uint32 `protobuf:"varint,10,opt,name=seda_payload_limit_in_bytes,json=sedaPayloadLimitInBytes,proto3" json:"seda_payload_limit_in_bytes,omitempty"` +} + +func (m *DrConfig) Reset() { *m = DrConfig{} } +func (m *DrConfig) String() string { return proto.CompactTextString(m) } +func (*DrConfig) ProtoMessage() {} +func (*DrConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_b5c0662d7d1478b0, []int{0} +} +func (m *DrConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *DrConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_DrConfig.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *DrConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_DrConfig.Merge(m, src) +} +func (m *DrConfig) XXX_Size() int { + return m.Size() +} +func (m *DrConfig) XXX_DiscardUnknown() { + xxx_messageInfo_DrConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_DrConfig proto.InternalMessageInfo + +func (m *DrConfig) GetCommitTimeoutInBlocks() uint32 { + if m != nil { + return m.CommitTimeoutInBlocks + } + return 0 +} + +func (m *DrConfig) GetRevealTimeoutInBlocks() uint32 { + if m != nil { + return m.RevealTimeoutInBlocks + } + return 0 +} + +func (m *DrConfig) GetBackupDelayInBlocks() uint32 { + if m != nil { + return m.BackupDelayInBlocks + } + return 0 +} + +func (m *DrConfig) GetDrRevealSizeLimitInBytes() uint32 { + if m != nil { + return m.DrRevealSizeLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetExecInputLimitInBytes() uint32 { + if m != nil { + return m.ExecInputLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetTallyInputLimitInBytes() uint32 { + if m != nil { + return m.TallyInputLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetConsensusFilterLimitInBytes() uint32 { + if m != nil { + return m.ConsensusFilterLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetMemoLimitInBytes() uint32 { + if m != nil { + return m.MemoLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetPaybackAddressLimitInBytes() uint32 { + if m != nil { + return m.PaybackAddressLimitInBytes + } + return 0 +} + +func (m *DrConfig) GetSedaPayloadLimitInBytes() uint32 { + if m != nil { + return m.SedaPayloadLimitInBytes + } + return 0 +} + +func init() { + proto.RegisterType((*DrConfig)(nil), "sedachain.core.v1.DrConfig") +} + +func init() { proto.RegisterFile("sedachain/core/v1/dr_config.proto", fileDescriptor_b5c0662d7d1478b0) } + +var fileDescriptor_b5c0662d7d1478b0 = []byte{ + // 405 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x92, 0x4f, 0x8b, 0x13, 0x31, + 0x18, 0x87, 0x3b, 0xba, 0xae, 0x6b, 0x40, 0xd0, 0x2e, 0xae, 0xe3, 0x2e, 0x8e, 0x7f, 0x4e, 0x5e, + 0x76, 0x86, 0x65, 0x0f, 0x8a, 0x08, 0xe2, 0x58, 0x84, 0x01, 0x0f, 0xb2, 0x7a, 0xf2, 0x12, 0x32, + 0xc9, 0xdb, 0x36, 0x34, 0x93, 0x0c, 0x49, 0xa6, 0x74, 0xfa, 0x29, 0xfc, 0x58, 0x1e, 0x7b, 0xf4, + 0xa6, 0xb4, 0x5f, 0x44, 0x92, 0x94, 0xd2, 0x99, 0xed, 0xb1, 0x3c, 0xcf, 0xf3, 0x6b, 0x18, 0x5e, + 0xf4, 0xca, 0x00, 0x23, 0x74, 0x4a, 0xb8, 0xcc, 0xa8, 0xd2, 0x90, 0xcd, 0xaf, 0x32, 0xa6, 0x31, + 0x55, 0x72, 0xcc, 0x27, 0x69, 0xad, 0x95, 0x55, 0xc3, 0xc7, 0x3b, 0x25, 0x75, 0x4a, 0x3a, 0xbf, + 0x7a, 0xfd, 0xf7, 0x08, 0x9d, 0x8c, 0xf4, 0x67, 0x6f, 0x0d, 0xdf, 0xa2, 0x98, 0xaa, 0xaa, 0xe2, + 0x16, 0x5b, 0x5e, 0x81, 0x6a, 0x2c, 0xe6, 0x12, 0x97, 0x42, 0xd1, 0x99, 0x89, 0xa3, 0x97, 0xd1, + 0x9b, 0x87, 0x37, 0x4f, 0x02, 0xff, 0x11, 0x70, 0x21, 0x73, 0x0f, 0x5d, 0xa8, 0x61, 0x0e, 0x44, + 0x1c, 0x08, 0xef, 0x84, 0x30, 0xf0, 0x7e, 0x78, 0x8d, 0xce, 0x4a, 0x42, 0x67, 0x4d, 0x8d, 0x19, + 0x08, 0xd2, 0xee, 0x65, 0x77, 0x7d, 0x76, 0x1a, 0xe8, 0xc8, 0xc1, 0x5d, 0xf4, 0x11, 0x3d, 0x67, + 0x1a, 0x6f, 0xff, 0xd0, 0xf0, 0x25, 0x60, 0xc1, 0xdd, 0xa3, 0x5d, 0xdc, 0x5a, 0x30, 0xf1, 0x91, + 0x6f, 0x63, 0xa6, 0x6f, 0xbc, 0xf3, 0x9d, 0x2f, 0xe1, 0xab, 0x33, 0x0a, 0x99, 0x3b, 0x3e, 0x7c, + 0x87, 0x9e, 0xc1, 0x02, 0x28, 0xe6, 0xb2, 0x6e, 0x6c, 0x3f, 0xbe, 0x17, 0xde, 0xeb, 0x84, 0xc2, + 0xf1, 0x4e, 0xf9, 0x1e, 0x9d, 0x5b, 0x22, 0x44, 0x7b, 0x38, 0x3d, 0xf6, 0xe9, 0x99, 0x37, 0x6e, + 0xb7, 0x23, 0xf4, 0x82, 0x2a, 0x69, 0x40, 0x9a, 0xc6, 0xe0, 0x31, 0x17, 0x16, 0x74, 0x7f, 0xe0, + 0xbe, 0x1f, 0xb8, 0xd8, 0x69, 0x5f, 0xbc, 0xd5, 0x59, 0xb9, 0x44, 0xa7, 0x15, 0x54, 0xaa, 0x5f, + 0x9e, 0xf8, 0xf2, 0x91, 0x43, 0x1d, 0x3d, 0x47, 0x49, 0x4d, 0x5a, 0xf7, 0x15, 0x31, 0x61, 0x4c, + 0x83, 0x31, 0xfd, 0xf2, 0x81, 0x2f, 0xcf, 0xb7, 0xd6, 0xa7, 0x20, 0x75, 0x36, 0x3e, 0xa0, 0x0b, + 0x77, 0x38, 0xb8, 0x26, 0xad, 0x50, 0x84, 0xf5, 0x07, 0x90, 0x1f, 0x78, 0xea, 0x94, 0x6f, 0xc1, + 0xd8, 0xaf, 0xf3, 0xe2, 0xf7, 0x3a, 0x89, 0x56, 0xeb, 0x24, 0xfa, 0xb7, 0x4e, 0xa2, 0x5f, 0x9b, + 0x64, 0xb0, 0xda, 0x24, 0x83, 0x3f, 0x9b, 0x64, 0xf0, 0x33, 0x9b, 0x70, 0x3b, 0x6d, 0xca, 0x94, + 0xaa, 0x2a, 0x73, 0xb5, 0x3f, 0x52, 0xaa, 0x84, 0xff, 0x71, 0x19, 0x4e, 0x79, 0x11, 0x8e, 0xd9, + 0xb6, 0x35, 0x98, 0xf2, 0xd8, 0x1b, 0xd7, 0xff, 0x03, 0x00, 0x00, 0xff, 0xff, 0x91, 0xdd, 0x66, + 0x42, 0xeb, 0x02, 0x00, 0x00, +} + +func (m *DrConfig) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *DrConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *DrConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.SedaPayloadLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.SedaPayloadLimitInBytes)) + i-- + dAtA[i] = 0x50 + } + if m.PaybackAddressLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.PaybackAddressLimitInBytes)) + i-- + dAtA[i] = 0x48 + } + if m.MemoLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.MemoLimitInBytes)) + i-- + dAtA[i] = 0x40 + } + if m.ConsensusFilterLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.ConsensusFilterLimitInBytes)) + i-- + dAtA[i] = 0x38 + } + if m.TallyInputLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.TallyInputLimitInBytes)) + i-- + dAtA[i] = 0x30 + } + if m.ExecInputLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.ExecInputLimitInBytes)) + i-- + dAtA[i] = 0x28 + } + if m.DrRevealSizeLimitInBytes != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.DrRevealSizeLimitInBytes)) + i-- + dAtA[i] = 0x20 + } + if m.BackupDelayInBlocks != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.BackupDelayInBlocks)) + i-- + dAtA[i] = 0x18 + } + if m.RevealTimeoutInBlocks != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.RevealTimeoutInBlocks)) + i-- + dAtA[i] = 0x10 + } + if m.CommitTimeoutInBlocks != 0 { + i = encodeVarintDrConfig(dAtA, i, uint64(m.CommitTimeoutInBlocks)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintDrConfig(dAtA []byte, offset int, v uint64) int { + offset -= sovDrConfig(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *DrConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.CommitTimeoutInBlocks != 0 { + n += 1 + sovDrConfig(uint64(m.CommitTimeoutInBlocks)) + } + if m.RevealTimeoutInBlocks != 0 { + n += 1 + sovDrConfig(uint64(m.RevealTimeoutInBlocks)) + } + if m.BackupDelayInBlocks != 0 { + n += 1 + sovDrConfig(uint64(m.BackupDelayInBlocks)) + } + if m.DrRevealSizeLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.DrRevealSizeLimitInBytes)) + } + if m.ExecInputLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.ExecInputLimitInBytes)) + } + if m.TallyInputLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.TallyInputLimitInBytes)) + } + if m.ConsensusFilterLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.ConsensusFilterLimitInBytes)) + } + if m.MemoLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.MemoLimitInBytes)) + } + if m.PaybackAddressLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.PaybackAddressLimitInBytes)) + } + if m.SedaPayloadLimitInBytes != 0 { + n += 1 + sovDrConfig(uint64(m.SedaPayloadLimitInBytes)) + } + return n +} + +func sovDrConfig(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozDrConfig(x uint64) (n int) { + return sovDrConfig(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *DrConfig) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: DrConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: DrConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CommitTimeoutInBlocks", wireType) + } + m.CommitTimeoutInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CommitTimeoutInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RevealTimeoutInBlocks", wireType) + } + m.RevealTimeoutInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RevealTimeoutInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field BackupDelayInBlocks", wireType) + } + m.BackupDelayInBlocks = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.BackupDelayInBlocks |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field DrRevealSizeLimitInBytes", wireType) + } + m.DrRevealSizeLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.DrRevealSizeLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecInputLimitInBytes", wireType) + } + m.ExecInputLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecInputLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyInputLimitInBytes", wireType) + } + m.TallyInputLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TallyInputLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusFilterLimitInBytes", wireType) + } + m.ConsensusFilterLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ConsensusFilterLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MemoLimitInBytes", wireType) + } + m.MemoLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MemoLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field PaybackAddressLimitInBytes", wireType) + } + m.PaybackAddressLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.PaybackAddressLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SedaPayloadLimitInBytes", wireType) + } + m.SedaPayloadLimitInBytes = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDrConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SedaPayloadLimitInBytes |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipDrConfig(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthDrConfig + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipDrConfig(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrConfig + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrConfig + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowDrConfig + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthDrConfig + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupDrConfig + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthDrConfig + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthDrConfig = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowDrConfig = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupDrConfig = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/core/types/errors.go b/x/core/types/errors.go new file mode 100644 index 00000000..928b1a3b --- /dev/null +++ b/x/core/types/errors.go @@ -0,0 +1,65 @@ +package types + +import ( + "cosmossdk.io/errors" +) + +var ( + ErrAlreadyAllowlisted = errors.Register("core", 2, "public key already exists in allowlist") + ErrNotAllowlisted = errors.Register("core", 3, "public key is not in allowlist") + ErrInsufficientStake = errors.Register("core", 4, "stake amount is insufficient") + ErrInvalidStakeProof = errors.Register("core", 5, "invalid stake proof") + ErrZeroReplicationFactor = errors.Register("core", 6, "replication factor cannot be zero") + ErrGasPriceTooLow = errors.Register("core", 7, "gas price is too low") + ErrGasPriceTooHigh = errors.Register("core", 8, "gas price must fit within 128 bits (unsigned)") + ErrExecGasLimitTooLow = errors.Register("core", 9, "exec gas limit is too low") + ErrTallyGasLimitTooLow = errors.Register("core", 10, "tally gas limit is too low") + ErrInvalidExecProgramID = errors.Register("core", 11, "exec program ID is not a valid hex string") + ErrInvalidTallyProgramID = errors.Register("core", 12, "tally program ID is not a valid hex string") + ErrInvalidLengthExecProgramID = errors.Register("core", 13, "hex-encoded exec program ID is not 64 characters long") + ErrInvalidLengthTallyProgramID = errors.Register("core", 14, "hex-encoded tally program ID is not 64 characters long") + ErrInvalidVersion = errors.Register("core", 15, "invalid data request version") + ErrExecInputLimitExceeded = errors.Register("core", 16, "exec input limit exceeded") + ErrTallyInputLimitExceeded = errors.Register("core", 17, "tally input limit exceeded") + ErrConsensusFilterLimitExceeded = errors.Register("core", 18, "consensus filter limit exceeded") + ErrMemoLimitExceeded = errors.Register("core", 19, "memo limit exceeded") + ErrPaybackAddressLimitExceeded = errors.Register("core", 20, "payback address limit exceeded") + ErrSEDAPayloadLimitExceeded = errors.Register("core", 21, "SEDA payload limit exceeded") + ErrReplicationFactorNotUint16 = errors.Register("core", 22, "replication factor must fit within 16 bits (unsigned)") + ErrReplicationFactorTooHigh = errors.Register("core", 23, "replication factor is too high") + ErrDataRequestAlreadyExists = errors.Register("core", 24, "data request already exists") + ErrNotCommitting = errors.Register("core", 25, "data request is not in committing state") + ErrAlreadyCommitted = errors.Register("core", 26, "commit under given public key already exists") + ErrCommitTimeout = errors.Register("core", 27, "commit timeout") + ErrRevealNotStarted = errors.Register("core", 28, "reveal phase has not started") + ErrDataRequestExpired = errors.Register("core", 29, "data request expired") + ErrNotCommitted = errors.Register("core", 30, "commit under given public key does not exist") + ErrAlreadyRevealed = errors.Register("core", 31, "reveal under given public key already exists") + ErrRevealTimeout = errors.Register("core", 32, "reveal timeout") + ErrRevealTooBig = errors.Register("core", 33, "reveal is too big") + ErrInvalidProxyPublicKey = errors.Register("core", 34, "invalid hex-encoded proxy public key") + ErrInvalidRevealExitCode = errors.Register("core", 35, "invalid reveal exit code") + ErrRevealMismatch = errors.Register("core", 36, "revealed result does not match the committed result") + ErrInvalidCommitProof = errors.Register("core", 37, "invalid commit proof") + ErrInvalidRevealProof = errors.Register("core", 38, "invalid reveal proof") + // Errors used in filter: + ErrInvalidFilterType = errors.Register("core", 39, "invalid filter type") + ErrFilterInputTooShort = errors.Register("core", 40, "filter input length too short") + ErrInvalidPathLen = errors.Register("core", 41, "invalid JSON path length") + ErrInvalidNumberType = errors.Register("core", 42, "invalid number type specified") + ErrInvalidFilterInput = errors.Register("core", 43, "invalid filter input") + ErrInvalidSigmaMultiplier = errors.Register("core", 44, "invalid sigma multiplier") + ErrOutOfTallyGas = errors.Register("core", 45, "out of tally gas") + ErrConsensusInError = errors.Register("core", 46, "consensus in error") + ErrNoConsensus = errors.Register("core", 47, "> 1/3 of reveals do not agree on reveal data") + ErrNoBasicConsensus = errors.Register("core", 48, "> 1/3 of reveals do not agree on (exit_code_success, proxy_pub_keys)") + ErrFilterDidNotRun = errors.Register("core", 49, "filter did not run") + // Errors used in tally program execution: + ErrDecodingPaybackAddress = errors.Register("core", 50, "failed to decode payback address") + ErrFindingTallyProgram = errors.Register("core", 51, "failed to find tally program") + ErrDecodingTallyInputs = errors.Register("core", 52, "failed to decode tally inputs") + ErrConstructingTallyVMArgs = errors.Register("core", 53, "failed to construct tally VM arguments") + ErrGettingMaxTallyGasLimit = errors.Register("core", 54, "failed to get max tally gas limit") + ErrInvalidStatusTransition = errors.Register("core", 55, "invalid status transition") + ErrDataRequestNotFoundInIndex = errors.Register("core", 56, "data request not found in index") +) diff --git a/x/tally/types/events.go b/x/core/types/events.go similarity index 83% rename from x/tally/types/events.go rename to x/core/types/events.go index 6a7d6f27..26fd0444 100644 --- a/x/tally/types/events.go +++ b/x/core/types/events.go @@ -1,8 +1,9 @@ package types const ( - EventTypeTallyCompletion = "tally_completion" - EventTypeGasMeter = "gas_calculation" + EventTypeTallyCompletion = "tally_completion" + EventTypeGasMeter = "gas_calculation" + EventTypeRemoveDataRequest = "seda-remove-dr" AttributeDataRequestID = "dr_id" AttributeDataRequestHeight = "dr_height" diff --git a/x/core/types/expected_keepers.go b/x/core/types/expected_keepers.go new file mode 100644 index 00000000..7c3c2931 --- /dev/null +++ b/x/core/types/expected_keepers.go @@ -0,0 +1,34 @@ +package types + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + + batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" + dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" + wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" +) + +type BatchingKeeper interface { + SetDataResultForBatching(ctx context.Context, result batchingtypes.DataResult) error +} + +type DataProxyKeeper interface { + GetDataProxyConfig(ctx context.Context, pubKey []byte) (result dataproxytypes.ProxyConfig, err error) +} + +type WasmStorageKeeper interface { + GetCoreContractAddr(ctx context.Context) (sdk.AccAddress, error) + GetOracleProgram(ctx context.Context, hash string) (wasmstoragetypes.OracleProgram, error) +} + +type StakingKeeper interface { + BondDenom(ctx context.Context) (string, error) +} + +type BankKeeper interface { + SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error + SendCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error + BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error +} diff --git a/x/tally/types/filters.go b/x/core/types/filters.go similarity index 100% rename from x/tally/types/filters.go rename to x/core/types/filters.go diff --git a/x/tally/types/codec_test.go b/x/core/types/filters_test.go similarity index 100% rename from x/tally/types/codec_test.go rename to x/core/types/filters_test.go diff --git a/x/tally/types/filters_util.go b/x/core/types/filters_util.go similarity index 89% rename from x/tally/types/filters_util.go rename to x/core/types/filters_util.go index 4ffc21fb..19483637 100644 --- a/x/tally/types/filters_util.go +++ b/x/core/types/filters_util.go @@ -1,7 +1,6 @@ package types import ( - "encoding/base64" "slices" "github.com/ohler55/ojg/gen" @@ -29,12 +28,7 @@ func parseReveals(reveals []Reveal, dataPath string, errors []bool) ([]string, d continue } - revealBytes, err := base64.StdEncoding.DecodeString(r.Reveal) - if err != nil { - errors[i] = true - continue - } - obj, err := parser.Parse(revealBytes) + obj, err := parser.Parse(r.Reveal) if err != nil { errors[i] = true continue diff --git a/x/tally/types/gas_meter.go b/x/core/types/gas_meter.go similarity index 87% rename from x/tally/types/gas_meter.go rename to x/core/types/gas_meter.go index 1595b4ed..0f95833d 100644 --- a/x/tally/types/gas_meter.go +++ b/x/core/types/gas_meter.go @@ -17,6 +17,16 @@ type GasMeter struct { execGasRemaining uint64 totalProxyGasPerExec uint64 postedGasPrice math.Int // gas price as posted, can be higher than the GasPrice on the request + poster string + escrow math.Int +} + +func (g *GasMeter) GetPoster() string { + return g.poster +} + +func (g *GasMeter) GetEscrow() math.Int { + return g.escrow } var _ HashSortable = ProxyGasUsed{} @@ -43,13 +53,15 @@ func (e ExecutorGasUsed) GetSortKey() []byte { } // NewGasMeter creates a new gas meter and incurs the base gas cost. -func NewGasMeter(tallyGasLimit, execGasLimit, maxTallyGasLimit uint64, postedGasPrice math.Int, baseGasCost uint64) *GasMeter { +func NewGasMeter(dr *DataRequest, maxTallyGasLimit uint64, baseGasCost uint64) *GasMeter { gasMeter := &GasMeter{ - tallyGasLimit: min(tallyGasLimit, maxTallyGasLimit), - tallyGasRemaining: min(tallyGasLimit, maxTallyGasLimit), - execGasLimit: execGasLimit, - execGasRemaining: execGasLimit, - postedGasPrice: postedGasPrice, + tallyGasLimit: min(dr.TallyGasLimit, maxTallyGasLimit), + tallyGasRemaining: min(dr.TallyGasLimit, maxTallyGasLimit), + execGasLimit: dr.ExecGasLimit, + execGasRemaining: dr.ExecGasLimit, + postedGasPrice: dr.PostedGasPrice, + poster: dr.Poster, + escrow: dr.Escrow, } // For normal operations we first check if the gas limit is enough to cover @@ -115,8 +127,8 @@ func (g *GasMeter) ConsumeTallyGas(amount uint64) bool { // ConsumeExecGasForProxy consumes execution gas for data proxy payout and records // the payout information. It returns true if the execution gas runs out during // the process. -func (g *GasMeter) ConsumeExecGasForProxy(proxyPubkey, payoutAddr string, gasUsedPerExec uint64, replicationFactor uint16) { - amount := gasUsedPerExec * uint64(replicationFactor) +func (g *GasMeter) ConsumeExecGasForProxy(proxyPubkey, payoutAddr string, gasUsedPerExec, replicationFactor uint64) { + amount := gasUsedPerExec * replicationFactor g.proxies = append(g.proxies, ProxyGasUsed{ PayoutAddress: payoutAddr, diff --git a/x/tally/types/genesis.go b/x/core/types/genesis.go similarity index 77% rename from x/tally/types/genesis.go rename to x/core/types/genesis.go index 911a28f6..bf19584d 100644 --- a/x/tally/types/genesis.go +++ b/x/core/types/genesis.go @@ -3,11 +3,12 @@ package types // DefaultGenesisState creates a default GenesisState object. func DefaultGenesisState() *GenesisState { return &GenesisState{ + // TODO add other states Params: DefaultParams(), } } -// ValidateGenesis validates batching genesis data. +// ValidateGenesis validates core genesis data. func ValidateGenesis(state GenesisState) error { return state.Params.Validate() } diff --git a/x/tally/types/genesis.pb.go b/x/core/types/genesis.pb.go similarity index 80% rename from x/tally/types/genesis.pb.go rename to x/core/types/genesis.pb.go index 9b078409..0c1a6ade 100644 --- a/x/tally/types/genesis.pb.go +++ b/x/core/types/genesis.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/tally/v1/genesis.proto +// source: sedachain/core/v1/genesis.proto package types @@ -23,7 +23,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -// GenesisState defines tally module's genesis state. +// GenesisState defines core module's genesis state. type GenesisState struct { Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } @@ -32,7 +32,7 @@ func (m *GenesisState) Reset() { *m = GenesisState{} } func (m *GenesisState) String() string { return proto.CompactTextString(m) } func (*GenesisState) ProtoMessage() {} func (*GenesisState) Descriptor() ([]byte, []int) { - return fileDescriptor_3460f907f9a828f3, []int{0} + return fileDescriptor_9ae62d9b0e76089c, []int{0} } func (m *GenesisState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -69,26 +69,26 @@ func (m *GenesisState) GetParams() Params { } func init() { - proto.RegisterType((*GenesisState)(nil), "sedachain.tally.v1.GenesisState") + proto.RegisterType((*GenesisState)(nil), "sedachain.core.v1.GenesisState") } -func init() { proto.RegisterFile("sedachain/tally/v1/genesis.proto", fileDescriptor_3460f907f9a828f3) } +func init() { proto.RegisterFile("sedachain/core/v1/genesis.proto", fileDescriptor_9ae62d9b0e76089c) } -var fileDescriptor_3460f907f9a828f3 = []byte{ - // 202 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x28, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x49, 0xcc, 0xc9, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, 0x4f, - 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x82, 0xab, - 0xd0, 0x03, 0xab, 0xd0, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x4b, 0xeb, 0x83, - 0x58, 0x10, 0x95, 0x52, 0x72, 0x58, 0xcc, 0x82, 0x68, 0x01, 0xcb, 0x2b, 0x79, 0x70, 0xf1, 0xb8, - 0x43, 0x8c, 0x0e, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xb2, 0xe0, 0x62, 0x2b, 0x48, 0x2c, 0x4a, 0xcc, - 0x2d, 0x96, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x36, 0x92, 0xd2, 0xc3, 0xb4, 0x4a, 0x2f, 0x00, 0xac, - 0xc2, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x7a, 0x27, 0xaf, 0x13, 0x8f, 0xe4, 0x18, - 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, - 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x48, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, - 0xcf, 0xd5, 0x07, 0x99, 0x06, 0xb6, 0x39, 0x39, 0x3f, 0x07, 0xcc, 0xd1, 0x85, 0x38, 0xae, 0x02, - 0xea, 0xbc, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x12, 0x63, 0x40, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xe4, 0x1d, 0x97, 0x73, 0x0a, 0x01, 0x00, 0x00, +var fileDescriptor_9ae62d9b0e76089c = []byte{ + // 200 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2f, 0x4e, 0x4d, 0x49, + 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x33, 0xd4, 0x4f, 0x4f, + 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0x2b, 0xd0, + 0x03, 0x29, 0xd0, 0x2b, 0x33, 0x94, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xea, 0x83, 0x58, + 0x10, 0x85, 0x52, 0x32, 0x98, 0x26, 0x81, 0x35, 0x80, 0x65, 0x95, 0xdc, 0xb9, 0x78, 0xdc, 0x21, + 0xe6, 0x06, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x99, 0x73, 0xb1, 0x15, 0x24, 0x16, 0x25, 0xe6, 0x16, + 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x49, 0xea, 0x61, 0xd8, 0xa3, 0x17, 0x00, 0x56, 0xe0, + 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x54, 0xb9, 0x93, 0xe7, 0x89, 0x47, 0x72, 0x8c, 0x17, + 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, + 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xe9, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, + 0xea, 0x83, 0x0c, 0x03, 0x5b, 0x9c, 0x9c, 0x9f, 0x03, 0xe6, 0xe8, 0x42, 0x5c, 0x56, 0x01, 0x71, + 0x5b, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0x85, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, + 0xb1, 0xd4, 0xc9, 0xae, 0x04, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { diff --git a/x/tally/types/hash_sort.go b/x/core/types/hash_sort.go similarity index 100% rename from x/tally/types/hash_sort.go rename to x/core/types/hash_sort.go diff --git a/x/tally/types/hash_sort_test.go b/x/core/types/hash_sort_test.go similarity index 100% rename from x/tally/types/hash_sort_test.go rename to x/core/types/hash_sort_test.go diff --git a/x/core/types/keys.go b/x/core/types/keys.go new file mode 100644 index 00000000..432e0acf --- /dev/null +++ b/x/core/types/keys.go @@ -0,0 +1,18 @@ +package types + +import "cosmossdk.io/collections" + +const ( + ModuleName = "core" + StoreKey = ModuleName +) + +var ( + AllowlistKey = collections.NewPrefix(0) + StakersKeyPrefix = collections.NewPrefix(1) + DataRequestsKeyPrefix = collections.NewPrefix(2) + RevealBodiesKeyPrefix = collections.NewPrefix(3) + DrIndexingKeyPrefix = collections.NewPrefix(4) + TimeoutQueueKeyPrefix = collections.NewPrefix(5) + ParamsKey = collections.NewPrefix(6) +) diff --git a/x/core/types/msgs.go b/x/core/types/msgs.go new file mode 100644 index 00000000..3ec9dee8 --- /dev/null +++ b/x/core/types/msgs.go @@ -0,0 +1,289 @@ +package types + +import ( + "encoding/binary" + "encoding/hex" + "math/big" + "strings" + + "golang.org/x/crypto/sha3" + "golang.org/x/mod/semver" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const ( + MinExecGasLimit uint64 = 10_000_000_000_000 // 10 teraGas + MinTallyGasLimit uint64 = 10_000_000_000_000 // 10 teraGas + MaxReplicationFactor uint32 = 100 +) + +var MinGasPrice = math.NewInt(2_000) + +func isBigIntUint128(x *big.Int) bool { + return x.Sign() >= 0 && x.BitLen() <= 128 +} + +// Validate validates the PostDataRequest message based on the given data +// request configurations. +func (m MsgPostDataRequest) Validate(config DataRequestConfig) error { + _, err := sdk.AccAddressFromBech32(m.Sender) + if err != nil { + return sdkerrors.ErrInvalidAddress.Wrapf("%s", err.Error()) + } + + if m.ReplicationFactor == 0 { + return ErrZeroReplicationFactor + } + // Ensure that the replication factor fits within 16 bits (unsigned). + if m.ReplicationFactor > uint32(^uint16(0)) { + return ErrReplicationFactorNotUint16 + } + + if m.GasPrice.IsNegative() || m.GasPrice.LT(MinGasPrice) { + return ErrGasPriceTooLow.Wrapf("%s < %s", m.GasPrice, MinGasPrice) + } + if !isBigIntUint128(m.GasPrice.BigInt()) { + return ErrGasPriceTooHigh + } + + if m.ExecGasLimit < MinExecGasLimit { + return ErrExecGasLimitTooLow.Wrapf("%d < %d", m.ExecGasLimit, MinExecGasLimit) + } + if m.TallyGasLimit < MinTallyGasLimit { + return ErrTallyGasLimitTooLow.Wrapf("%d < %d", m.TallyGasLimit, MinTallyGasLimit) + } + + if _, err := hex.DecodeString(m.ExecProgramId); err != nil { + return ErrInvalidExecProgramID + } + if _, err := hex.DecodeString(m.TallyProgramId); err != nil { + return ErrInvalidTallyProgramID + } + if len(m.ExecProgramId) != 64 { + return ErrInvalidLengthExecProgramID.Wrapf("given ID is %d characters long", len(m.ExecProgramId)) + } + if len(m.TallyProgramId) != 64 { + return ErrInvalidLengthTallyProgramID.Wrapf("given ID is %d characters long", len(m.TallyProgramId)) + } + + if !semver.IsValid("v"+m.Version) || semver.Prerelease("v"+m.Version) != "" || semver.Build("v"+m.Version) != "" { + return ErrInvalidVersion.Wrapf("%s", m.Version) + } + + if len(m.ExecInputs) > int(config.ExecInputLimitInBytes) { + return ErrExecInputLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.ExecInputs), config.ExecInputLimitInBytes) + } + if len(m.TallyInputs) > int(config.TallyInputLimitInBytes) { + return ErrTallyInputLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.TallyInputs), config.TallyInputLimitInBytes) + } + if len(m.ConsensusFilter) > int(config.ConsensusFilterLimitInBytes) { + return ErrConsensusFilterLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.ConsensusFilter), config.ConsensusFilterLimitInBytes) + } + if len(m.Memo) > int(config.MemoLimitInBytes) { + return ErrMemoLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.Memo), config.MemoLimitInBytes) + } + if len(m.PaybackAddress) > int(config.PaybackAddressLimitInBytes) { + return ErrPaybackAddressLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.PaybackAddress), config.PaybackAddressLimitInBytes) + } + if len(m.SEDAPayload) > int(config.SEDAPayloadLimitInBytes) { + return ErrSEDAPayloadLimitExceeded.Wrapf("%d bytes > %d bytes", len(m.SEDAPayload), config.SEDAPayloadLimitInBytes) + } + + return nil +} + +// MsgHash returns the hex-encoded hash of the PostDataRequest message to be used +// as the data request ID. +func (m *MsgPostDataRequest) MsgHash() (string, error) { + execProgramIDBytes, err := hex.DecodeString(m.ExecProgramId) + if err != nil { + return "", err + } + tallyProgramIDBytes, err := hex.DecodeString(m.TallyProgramId) + if err != nil { + return "", err + } + + execInputsHasher := sha3.NewLegacyKeccak256() + execInputsHasher.Write(m.ExecInputs) + execInputsHash := execInputsHasher.Sum(nil) + + tallyInputsHasher := sha3.NewLegacyKeccak256() + tallyInputsHasher.Write(m.TallyInputs) + tallyInputsHash := tallyInputsHasher.Sum(nil) + + consensusFilterHasher := sha3.NewLegacyKeccak256() + consensusFilterHasher.Write(m.ConsensusFilter) + consensusFilterHash := consensusFilterHasher.Sum(nil) + + memoHasher := sha3.NewLegacyKeccak256() + memoHasher.Write(m.Memo) + memoHash := memoHasher.Sum(nil) + + execGasLimitBytes := make([]byte, 8) + binary.BigEndian.PutUint64(execGasLimitBytes, m.ExecGasLimit) + tallyGasLimitBytes := make([]byte, 8) + binary.BigEndian.PutUint64(tallyGasLimitBytes, m.TallyGasLimit) + replicationFactorBytes := make([]byte, 2) + //nolint:gosec // G115: No overflow guaranteed by validation logic. + binary.BigEndian.PutUint16(replicationFactorBytes, uint16(m.ReplicationFactor)) + + dataRequestHasher := sha3.NewLegacyKeccak256() + dataRequestHasher.Write([]byte(m.Version)) + dataRequestHasher.Write(execProgramIDBytes) + dataRequestHasher.Write(execInputsHash) + dataRequestHasher.Write(execGasLimitBytes) + dataRequestHasher.Write(tallyProgramIDBytes) + dataRequestHasher.Write(tallyInputsHash) + dataRequestHasher.Write(tallyGasLimitBytes) + dataRequestHasher.Write(replicationFactorBytes) + dataRequestHasher.Write(consensusFilterHash) + dataRequestHasher.Write(m.GasPrice.BigInt().Bytes()) + dataRequestHasher.Write(memoHash) + + return hex.EncodeToString(dataRequestHasher.Sum(nil)), nil +} + +// Validate validates the PostDataRequest message based on the given data +// request configurations. +func (m MsgReveal) Validate(config DataRequestConfig, replicationFactor uint32) error { + // Ensure that the exit code fits within 8 bits (unsigned). + if m.RevealBody.ExitCode > uint32(^uint8(0)) { + return ErrInvalidRevealExitCode + } + + revealSizeLimit := config.DrRevealSizeLimitInBytes / replicationFactor + if len(m.RevealBody.Reveal) > int(revealSizeLimit) { + return ErrRevealTooBig.Wrapf("%d bytes > %d bytes", len(m.RevealBody.Reveal), revealSizeLimit) + } + + for _, key := range m.RevealBody.ProxyPubKeys { + _, err := hex.DecodeString(key) + if err != nil { + return ErrInvalidProxyPublicKey.Wrapf("%s", err.Error()) + } + } + return nil +} + +// TODO Remove contractAddr +// StakeHash computes the stake hash. +func (m MsgStake) MsgHash(_, chainID string, sequenceNum uint64) ([]byte, error) { + memoBytes, err := hex.DecodeString(m.Memo) + if err != nil { + return nil, err + } + memoHasher := sha3.NewLegacyKeccak256() + memoHasher.Write(memoBytes) + memoHash := memoHasher.Sum(nil) + + // Write to last 8 bytes of 16-byte variable. + // TODO contract used uint128 + seqBytes := make([]byte, 16) + binary.BigEndian.PutUint64(seqBytes[8:], sequenceNum) + + allBytes := append([]byte{}, "stake"...) + allBytes = append(allBytes, memoHash...) + allBytes = append(allBytes, chainID...) + // allBytes = append(allBytes, contractAddr...) // TODO Do not include contractAddr + allBytes = append(allBytes, seqBytes...) + + hasher := sha3.NewLegacyKeccak256() + hasher.Write(allBytes) + return hasher.Sum(nil), nil +} + +// TODO Remove contractAddr +// CommitHash computes the commit hash. +func (m MsgCommit) MsgHash(_, chainID string, drHeight int64) ([]byte, error) { + drHeightBytes := make([]byte, 8) + //nolint:gosec // G115: Block height is never negative. + binary.BigEndian.PutUint64(drHeightBytes, uint64(drHeight)) + + allBytes := append([]byte{}, "commit_data_result"...) + allBytes = append(allBytes, m.DrId...) + allBytes = append(allBytes, drHeightBytes...) + allBytes = append(allBytes, m.Commit...) + allBytes = append(allBytes, chainID...) + // allBytes = append(allBytes, contractAddr...) // TODO Do not include contractAddr + + hasher := sha3.NewLegacyKeccak256() + hasher.Write(allBytes) + return hasher.Sum(nil), nil +} + +// TODO Remove contractAddr +func (m MsgReveal) MsgHash(_, chainID string) ([]byte, error) { + revealBodyHash, err := m.RevealBody.RevealBodyHash() + if err != nil { + return nil, err + } + + allBytes := append([]byte("reveal_data_result"), revealBodyHash...) + allBytes = append(allBytes, chainID...) + // allBytes = append(allBytes, contractAddr...) + + hasher := sha3.NewLegacyKeccak256() + hasher.Write(allBytes) + return hasher.Sum(nil), nil +} + +// RevealHash computes the hash of the reveal contents. This hash is used by +// executors as their commit value. +func (m MsgReveal) RevealHash() ([]byte, error) { + revealBodyHash, err := m.RevealBody.RevealBodyHash() + if err != nil { + return nil, err + } + + hasher := sha3.NewLegacyKeccak256() + hasher.Write([]byte("reveal_message")) + hasher.Write(revealBodyHash) + hasher.Write([]byte(m.PublicKey)) + hasher.Write([]byte(m.Proof)) + hasher.Write([]byte(strings.Join(m.Stderr, ""))) + hasher.Write([]byte(strings.Join(m.Stdout, ""))) + + return hasher.Sum(nil), nil +} + +func (rb RevealBody) RevealBodyHash() ([]byte, error) { + revealHasher := sha3.NewLegacyKeccak256() + revealHasher.Write(rb.Reveal) + revealHash := revealHasher.Sum(nil) + + hasher := sha3.NewLegacyKeccak256() + + idBytes, err := hex.DecodeString(rb.DrId) + if err != nil { + return nil, err + } + hasher.Write(idBytes) + + reqHeightBytes := make([]byte, 8) + binary.BigEndian.PutUint64(reqHeightBytes, rb.DrBlockHeight) + hasher.Write(reqHeightBytes) + + // TODO RevealBody validator should bind rb.ExitCode value? + hasher.Write([]byte{byte(rb.ExitCode)}) + + gasUsedBytes := make([]byte, 8) + binary.BigEndian.PutUint64(gasUsedBytes, rb.GasUsed) + hasher.Write(gasUsedBytes) + + hasher.Write(revealHash) + + proxyPubKeyHasher := sha3.NewLegacyKeccak256() + for _, key := range rb.ProxyPubKeys { + keyHasher := sha3.NewLegacyKeccak256() + keyHasher.Write([]byte(key)) + proxyPubKeyHasher.Write(keyHasher.Sum(nil)) + } + hasher.Write(proxyPubKeyHasher.Sum(nil)) + + return hasher.Sum(nil), nil +} diff --git a/x/core/types/msgs_test.go b/x/core/types/msgs_test.go new file mode 100644 index 00000000..ee3db8d5 --- /dev/null +++ b/x/core/types/msgs_test.go @@ -0,0 +1,213 @@ +package types + +import ( + "testing" + + "cosmossdk.io/math" + "github.com/stretchr/testify/require" +) + +func TestMsgPostDataRequest_Validate(t *testing.T) { + validProgramID := "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef" + validConfig := DefaultParams().DataRequestConfig + validSender := "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f" + validVersion := "1.0.0" + + tests := []struct { + name string + msg MsgPostDataRequest + config DataRequestConfig + wantErr error + }{ + { + name: "valid message", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 65535, // max uint16 value + GasPrice: func() math.Int { + max, ok := math.NewIntFromString("340282366920938463463374607431768211455") // max uint128 value + require.True(t, ok) + return max + }(), + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + ExecInputs: make([]byte, 100), + TallyInputs: make([]byte, 100), + ConsensusFilter: make([]byte, 100), + Memo: make([]byte, 100), + PaybackAddress: make([]byte, 100), + SEDAPayload: make([]byte, 100), + }, + config: validConfig, + wantErr: nil, + }, + { + name: "zero replication factor", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 0, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrZeroReplicationFactor, + }, + { + name: "replication factor too high (exceeds uint16)", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 65536, // exceeds uint16 + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrReplicationFactorNotUint16, + }, + { + name: "gas price too low", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice.Sub(math.NewInt(1)), + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrGasPriceTooLow, + }, + { + name: "gas price too high (exceeds uint128)", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: func() math.Int { + max, ok := math.NewIntFromString("340282366920938463463374607431768211456") + require.True(t, ok) + return max + }(), + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrGasPriceTooHigh, + }, + { + name: "exec gas limit too low", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit - 1, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrExecGasLimitTooLow, + }, + { + name: "tally gas limit too low", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit - 1, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrTallyGasLimitTooLow, + }, + { + name: "exec program ID is not hex (odd length)", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdefa", + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrInvalidExecProgramID, + }, + { + name: "tally program ID is not hex", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdzz", + }, + config: validConfig, + wantErr: ErrInvalidTallyProgramID, + }, + { + name: "tally program ID too long", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: validVersion, + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID + "ab", + }, + config: validConfig, + wantErr: ErrInvalidLengthTallyProgramID, + }, + { + name: "invalid version", + msg: MsgPostDataRequest{ + Sender: validSender, + ReplicationFactor: 5, + GasPrice: MinGasPrice, + Version: "1.0.0-alpha.1", + ExecGasLimit: MinExecGasLimit, + TallyGasLimit: MinTallyGasLimit, + ExecProgramId: validProgramID, + TallyProgramId: validProgramID, + }, + config: validConfig, + wantErr: ErrInvalidVersion, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.Validate(tt.config) + if tt.wantErr != nil { + require.ErrorIs(t, err, tt.wantErr) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/core/types/params.go b/x/core/types/params.go new file mode 100644 index 00000000..baffadb7 --- /dev/null +++ b/x/core/types/params.go @@ -0,0 +1,177 @@ +package types + +import ( + "fmt" + + "cosmossdk.io/math" + + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +var ( + DefaultMinimumStake = math.NewInt(1000000000000000000) + DefaultBurnRatio = math.LegacyNewDecWithPrec(2, 1) +) + +const ( + // StakingConfig + DefaultAllowlistEnabled bool = true + + // DataRequestConfig + DefaultCommitTimeoutInBlocks uint32 = 50 + DefaultRevealTimeoutInBlocks uint32 = 5 + DefaultBackupDelayInBlocks uint32 = 5 + DefaultDrRevealSizeLimitInBytes uint32 = 24000 // 24 KB + DefaultExecInputLimitInBytes uint32 = 2048 // 2 KB + DefaultTallyInputLimitInBytes uint32 = 512 // 512 B + DefaultConsensusFilterLimitInBytes uint32 = 512 // 512 B + DefaultMemoLimitInBytes uint32 = 512 // 512 B + DefaultPaybackAddressLimitInBytes uint32 = 128 // 128 B + DefaultSEDAPayloadLimitInBytes uint32 = 512 // 512 B + + // TallyConfig + DefaultMaxResultSize = 1024 + DefaultMaxTallyGasLimit = 50_000_000_000_000 + DefaultFilterGasCostNone = 100_000 + DefaultFilterGasCostMultiplierMode = 100_000 + DefaultFilterGasCostMultiplierMAD = 100_000 + DefaultGasCostBase = 1_000_000_000_000 + DefaultExecutionGasCostFallback = 5_000_000_000_000 + DefaultMaxTalliesPerBlock = 100 +) + +// DefaultParams returns default core module parameters. +func DefaultParams() Params { + return Params{ + DataRequestConfig: DataRequestConfig{ + CommitTimeoutInBlocks: DefaultCommitTimeoutInBlocks, + RevealTimeoutInBlocks: DefaultRevealTimeoutInBlocks, + BackupDelayInBlocks: DefaultBackupDelayInBlocks, + DrRevealSizeLimitInBytes: DefaultDrRevealSizeLimitInBytes, + ExecInputLimitInBytes: DefaultExecInputLimitInBytes, + TallyInputLimitInBytes: DefaultTallyInputLimitInBytes, + ConsensusFilterLimitInBytes: DefaultConsensusFilterLimitInBytes, + MemoLimitInBytes: DefaultMemoLimitInBytes, + PaybackAddressLimitInBytes: DefaultPaybackAddressLimitInBytes, + SEDAPayloadLimitInBytes: DefaultSEDAPayloadLimitInBytes, + }, + StakingConfig: StakingConfig{ + MinimumStake: DefaultMinimumStake, + AllowlistEnabled: DefaultAllowlistEnabled, + }, + TallyConfig: TallyConfig{ + MaxResultSize: DefaultMaxResultSize, + MaxTallyGasLimit: DefaultMaxTallyGasLimit, + FilterGasCostNone: DefaultFilterGasCostNone, + FilterGasCostMultiplierMode: DefaultFilterGasCostMultiplierMode, + FilterGasCostMultiplierMAD: DefaultFilterGasCostMultiplierMAD, + GasCostBase: DefaultGasCostBase, + ExecutionGasCostFallback: DefaultExecutionGasCostFallback, + BurnRatio: DefaultBurnRatio, + MaxTalliesPerBlock: DefaultMaxTalliesPerBlock, + }, + } +} + +// ValidateBasic performs basic validation on core module parameters. +func (p *Params) Validate() error { + err := p.DataRequestConfig.Validate() + if err != nil { + return err + } + err = p.StakingConfig.Validate() + if err != nil { + return err + } + err = p.TallyConfig.Validate() + if err != nil { + return err + } + return nil +} + +func (dc *DataRequestConfig) Validate() error { + if dc.CommitTimeoutInBlocks <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("commit timeout must be greater than 0: %d blocks", dc.CommitTimeoutInBlocks) + } + if dc.RevealTimeoutInBlocks <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("reveal timeout must be greater than 0: %d blocks", dc.RevealTimeoutInBlocks) + } + if dc.BackupDelayInBlocks <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("backup delay must be greater than 0: %d blocks", dc.BackupDelayInBlocks) + } + if dc.DrRevealSizeLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("reveal size limit must be greater than 0: %d bytes", dc.DrRevealSizeLimitInBytes) + } + if dc.ExecInputLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("exec input limit must be greater than 0: %d bytes", dc.ExecInputLimitInBytes) + } + if dc.TallyInputLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("tally input limit must be greater than 0: %d bytes", dc.TallyInputLimitInBytes) + } + if dc.ConsensusFilterLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("consensus filter limit must be greater than 0: %d bytes", dc.ConsensusFilterLimitInBytes) + } + if dc.MemoLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("memo limit must be greater than 0: %d bytes", dc.MemoLimitInBytes) + } + if dc.PaybackAddressLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("payback address limit must be greater than 0: %d bytes", dc.PaybackAddressLimitInBytes) + } + if dc.SEDAPayloadLimitInBytes <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("SEDA payload limit must be greater than 0: %d bytes", dc.SEDAPayloadLimitInBytes) + } + return nil +} + +func (sc *StakingConfig) Validate() error { + if !sc.MinimumStake.IsPositive() { + return sdkerrors.ErrInvalidRequest.Wrapf("minimum stake must be positive: %s", sc.MinimumStake) + } + return nil +} + +func (tc *TallyConfig) Validate() error { + if tc.MaxResultSize <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("max result size must be greater than 0: %d", tc.MaxResultSize) + } + if tc.MaxTallyGasLimit <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("max tally gas limit must be greater than 0: %d", tc.MaxTallyGasLimit) + } + if tc.FilterGasCostNone <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (none) must be greater than 0: %d", tc.FilterGasCostNone) + } + if tc.FilterGasCostMultiplierMode <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (mode) must be greater than 0: %d", tc.FilterGasCostMultiplierMode) + } + if tc.FilterGasCostMultiplierMAD <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (MAD) must be greater than 0: %d", tc.FilterGasCostMultiplierMAD) + } + if tc.GasCostBase <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("base gas cost must be greater than 0: %d", tc.GasCostBase) + } + if tc.ExecutionGasCostFallback <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("execution gas cost fallback must be greater than 0: %d", tc.ExecutionGasCostFallback) + } + if tc.MaxTalliesPerBlock <= 0 { + return sdkerrors.ErrInvalidRequest.Wrapf("max tallies per block must be greater than 0: %d", tc.MaxTalliesPerBlock) + } + return validateBurnRatio(tc.BurnRatio) +} + +func validateBurnRatio(i interface{}) error { + v, ok := i.(math.LegacyDec) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + if v.IsNil() { + return fmt.Errorf("burn ratio must be not nil") + } + if v.IsNegative() { + return fmt.Errorf("burn ratio must be positive: %s", v) + } + if v.GT(math.LegacyOneDec()) { + return fmt.Errorf("burn ratio too large: %s", v) + } + return nil +} diff --git a/x/tally/types/query.pb.go b/x/core/types/query.pb.go similarity index 83% rename from x/tally/types/query.pb.go rename to x/core/types/query.pb.go index e1a2f6f1..7fb88080 100644 --- a/x/tally/types/query.pb.go +++ b/x/core/types/query.pb.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/tally/v1/query.proto +// source: sedachain/core/v1/query.proto package types @@ -37,7 +37,7 @@ func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ff9d68418bcd9e65, []int{0} + return fileDescriptor_0d8090940a863ab0, []int{0} } func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -68,7 +68,7 @@ var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo // QueryParamsResponse is the response type for the Query/Params RPC method. type QueryParamsResponse struct { - // params defines the parameters of the module. + // Params defines the parameters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } @@ -76,7 +76,7 @@ func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ff9d68418bcd9e65, []int{1} + return fileDescriptor_0d8090940a863ab0, []int{1} } func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -113,32 +113,32 @@ func (m *QueryParamsResponse) GetParams() Params { } func init() { - proto.RegisterType((*QueryParamsRequest)(nil), "sedachain.tally.v1.QueryParamsRequest") - proto.RegisterType((*QueryParamsResponse)(nil), "sedachain.tally.v1.QueryParamsResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "sedachain.core.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "sedachain.core.v1.QueryParamsResponse") } -func init() { proto.RegisterFile("sedachain/tally/v1/query.proto", fileDescriptor_ff9d68418bcd9e65) } +func init() { proto.RegisterFile("sedachain/core/v1/query.proto", fileDescriptor_0d8090940a863ab0) } -var fileDescriptor_ff9d68418bcd9e65 = []byte{ +var fileDescriptor_0d8090940a863ab0 = []byte{ // 281 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2b, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x49, 0xcc, 0xc9, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, 0x2f, - 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x82, 0xcb, 0xeb, 0x81, - 0xe5, 0xf5, 0xca, 0x0c, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, - 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0x3a, 0xa4, 0x44, - 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0x8a, 0xcd, 0x1e, 0x88, 0x81, 0x60, - 0x79, 0x25, 0x11, 0x2e, 0xa1, 0x40, 0x90, 0xb5, 0x01, 0x89, 0x45, 0x89, 0xb9, 0xc5, 0x41, 0xa9, - 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x4a, 0xfe, 0x5c, 0xc2, 0x28, 0xa2, 0xc5, 0x05, 0xf9, 0x79, 0xc5, - 0xa9, 0x42, 0x16, 0x5c, 0x6c, 0x05, 0x60, 0x11, 0x09, 0x46, 0x05, 0x46, 0x0d, 0x6e, 0x23, 0x29, - 0x3d, 0x4c, 0x57, 0xea, 0x41, 0xf4, 0x38, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0x55, 0x6f, - 0xd4, 0xc2, 0xc8, 0xc5, 0x0a, 0x36, 0x51, 0xa8, 0x9a, 0x8b, 0x0d, 0xa2, 0x42, 0x48, 0x0d, 0x9b, - 0x6e, 0x4c, 0xc7, 0x48, 0xa9, 0x13, 0x54, 0x07, 0x71, 0x9e, 0x92, 0x42, 0xd3, 0xe5, 0x27, 0x93, - 0x99, 0xa4, 0x84, 0x24, 0xf4, 0x41, 0x1a, 0x74, 0x91, 0x7d, 0x0d, 0x71, 0x86, 0x93, 0xd7, 0x89, - 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, - 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x19, 0xa4, 0x67, 0x96, 0x64, 0x94, 0x26, - 0xe9, 0x25, 0xe7, 0xe7, 0x82, 0x75, 0x83, 0x43, 0x27, 0x39, 0x3f, 0x07, 0xd9, 0xa8, 0x0a, 0xa8, - 0x61, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x25, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x2b, 0xc6, 0xba, 0xa7, 0xca, 0x01, 0x00, 0x00, + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2d, 0x4e, 0x4d, 0x49, + 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x4f, 0xce, 0x2f, 0x4a, 0xd5, 0x2f, 0x33, 0xd4, 0x2f, 0x2c, + 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x84, 0x4b, 0xeb, 0x81, 0xa4, + 0xf5, 0xca, 0x0c, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, 0x13, 0x0b, 0x32, 0xf5, + 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x21, 0x1a, 0xa4, 0x44, 0xd2, + 0xf3, 0xd3, 0xf3, 0xc1, 0x4c, 0x7d, 0x10, 0x0b, 0x2a, 0x2a, 0x83, 0x69, 0x0b, 0xd8, 0x38, 0xb0, + 0xac, 0x92, 0x08, 0x97, 0x50, 0x20, 0xc8, 0xce, 0x80, 0xc4, 0xa2, 0xc4, 0xdc, 0xe2, 0xa0, 0xd4, + 0xc2, 0xd2, 0xd4, 0xe2, 0x12, 0x25, 0x3f, 0x2e, 0x61, 0x14, 0xd1, 0xe2, 0x82, 0xfc, 0xbc, 0xe2, + 0x54, 0x21, 0x73, 0x2e, 0xb6, 0x02, 0xb0, 0x88, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0xa4, + 0x1e, 0x86, 0x13, 0xf5, 0x20, 0x5a, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0x2a, 0x37, + 0x6a, 0x64, 0xe4, 0x62, 0x05, 0x1b, 0x28, 0x54, 0xc1, 0xc5, 0x06, 0x51, 0x21, 0xa4, 0x8a, 0x45, + 0x33, 0xa6, 0x53, 0xa4, 0xd4, 0x08, 0x29, 0x83, 0xb8, 0x4d, 0x49, 0xbe, 0xe9, 0xf2, 0x93, 0xc9, + 0x4c, 0x92, 0x42, 0xe2, 0xfa, 0x20, 0xf5, 0xba, 0x48, 0x1e, 0x86, 0xb8, 0xc1, 0xc9, 0xf3, 0xc4, + 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, + 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0xf4, 0xd3, 0x33, 0x4b, 0x32, 0x4a, 0x93, + 0xf4, 0x92, 0xf3, 0x73, 0xc1, 0x9a, 0xc1, 0x21, 0x93, 0x9c, 0x9f, 0x83, 0x6c, 0x52, 0x05, 0xc4, + 0xac, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0xb0, 0x0a, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, + 0xff, 0x3b, 0x8b, 0x8a, 0x2a, 0xc1, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -153,7 +153,7 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Params returns the total set of tally parameters. + // Params returns the total set of core parameters. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } @@ -167,7 +167,7 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { out := new(QueryParamsResponse) - err := c.cc.Invoke(ctx, "/sedachain.tally.v1.Query/Params", in, out, opts...) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Query/Params", in, out, opts...) if err != nil { return nil, err } @@ -176,7 +176,7 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { - // Params returns the total set of tally parameters. + // Params returns the total set of core parameters. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } @@ -202,7 +202,7 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/sedachain.tally.v1.Query/Params", + FullMethod: "/sedachain.core.v1.Query/Params", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) @@ -212,7 +212,7 @@ func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interf var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ - ServiceName: "sedachain.tally.v1.Query", + ServiceName: "sedachain.core.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ { @@ -221,7 +221,7 @@ var _Query_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{}, - Metadata: "sedachain/tally/v1/query.proto", + Metadata: "sedachain/core/v1/query.proto", } func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { diff --git a/x/tally/types/query.pb.gw.go b/x/core/types/query.pb.gw.go similarity index 97% rename from x/tally/types/query.pb.gw.go rename to x/core/types/query.pb.gw.go index 2c6580b0..5330f980 100644 --- a/x/tally/types/query.pb.gw.go +++ b/x/core/types/query.pb.gw.go @@ -1,5 +1,5 @@ // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. -// source: sedachain/tally/v1/query.proto +// source: sedachain/core/v1/query.proto /* Package types is a reverse proxy. @@ -145,7 +145,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"seda-chain", "tally", "params"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"seda-chain", "core", "params"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( diff --git a/x/tally/types/sigma_multiplier.go b/x/core/types/sigma_multiplier.go similarity index 100% rename from x/tally/types/sigma_multiplier.go rename to x/core/types/sigma_multiplier.go diff --git a/x/tally/types/sigma_multiplier_test.go b/x/core/types/sigma_multiplier_test.go similarity index 100% rename from x/tally/types/sigma_multiplier_test.go rename to x/core/types/sigma_multiplier_test.go diff --git a/x/tally/types/telemetry.go b/x/core/types/telemetry.go similarity index 100% rename from x/tally/types/telemetry.go rename to x/core/types/telemetry.go diff --git a/x/core/types/tx.pb.go b/x/core/types/tx.pb.go new file mode 100644 index 00000000..7f0c792e --- /dev/null +++ b/x/core/types/tx.pb.go @@ -0,0 +1,3797 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: sedachain/core/v1/tx.proto + +package types + +import ( + context "context" + cosmossdk_io_math "cosmossdk.io/math" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// The request message for the AddToAllowlist method. +type MsgAddToAllowlist struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + PublicKey string `protobuf:"bytes,2,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` +} + +func (m *MsgAddToAllowlist) Reset() { *m = MsgAddToAllowlist{} } +func (m *MsgAddToAllowlist) String() string { return proto.CompactTextString(m) } +func (*MsgAddToAllowlist) ProtoMessage() {} +func (*MsgAddToAllowlist) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{0} +} +func (m *MsgAddToAllowlist) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddToAllowlist) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddToAllowlist.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddToAllowlist) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddToAllowlist.Merge(m, src) +} +func (m *MsgAddToAllowlist) XXX_Size() int { + return m.Size() +} +func (m *MsgAddToAllowlist) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddToAllowlist.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddToAllowlist proto.InternalMessageInfo + +func (m *MsgAddToAllowlist) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgAddToAllowlist) GetPublicKey() string { + if m != nil { + return m.PublicKey + } + return "" +} + +// The response message for the AddToAllowlist method. +type MsgAddToAllowlistResponse struct { +} + +func (m *MsgAddToAllowlistResponse) Reset() { *m = MsgAddToAllowlistResponse{} } +func (m *MsgAddToAllowlistResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddToAllowlistResponse) ProtoMessage() {} +func (*MsgAddToAllowlistResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{1} +} +func (m *MsgAddToAllowlistResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddToAllowlistResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddToAllowlistResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddToAllowlistResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddToAllowlistResponse.Merge(m, src) +} +func (m *MsgAddToAllowlistResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddToAllowlistResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddToAllowlistResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddToAllowlistResponse proto.InternalMessageInfo + +// The request message for the Stake method. +type MsgStake struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + PublicKey string `protobuf:"bytes,2,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + Memo string `protobuf:"bytes,3,opt,name=memo,proto3" json:"memo,omitempty"` + // Proof is hex-encoded proof of the identity. + Proof string `protobuf:"bytes,4,opt,name=proof,proto3" json:"proof,omitempty"` + Stake types.Coin `protobuf:"bytes,5,opt,name=stake,proto3" json:"stake"` +} + +func (m *MsgStake) Reset() { *m = MsgStake{} } +func (m *MsgStake) String() string { return proto.CompactTextString(m) } +func (*MsgStake) ProtoMessage() {} +func (*MsgStake) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{2} +} +func (m *MsgStake) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStake) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStake.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStake) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStake.Merge(m, src) +} +func (m *MsgStake) XXX_Size() int { + return m.Size() +} +func (m *MsgStake) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStake.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStake proto.InternalMessageInfo + +func (m *MsgStake) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgStake) GetPublicKey() string { + if m != nil { + return m.PublicKey + } + return "" +} + +func (m *MsgStake) GetMemo() string { + if m != nil { + return m.Memo + } + return "" +} + +func (m *MsgStake) GetProof() string { + if m != nil { + return m.Proof + } + return "" +} + +func (m *MsgStake) GetStake() types.Coin { + if m != nil { + return m.Stake + } + return types.Coin{} +} + +// The response message for the Stake method. +type MsgStakeResponse struct { +} + +func (m *MsgStakeResponse) Reset() { *m = MsgStakeResponse{} } +func (m *MsgStakeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgStakeResponse) ProtoMessage() {} +func (*MsgStakeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{3} +} +func (m *MsgStakeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgStakeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgStakeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgStakeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgStakeResponse.Merge(m, src) +} +func (m *MsgStakeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgStakeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgStakeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgStakeResponse proto.InternalMessageInfo + +// The request message for the PostDataRequest method. +type MsgPostDataRequest struct { + // Poster of the data request + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + // Funds attached to the data request posting + Funds types.Coin `protobuf:"bytes,2,opt,name=funds,proto3" json:"funds"` + // Semantic versioning + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + // Hex-encoded ID (hash) of the execution program + ExecProgramId string `protobuf:"bytes,4,opt,name=exec_program_id,json=execProgramId,proto3" json:"exec_program_id,omitempty"` + // Inputs for the execution program + ExecInputs []byte `protobuf:"bytes,5,opt,name=exec_inputs,json=execInputs,proto3" json:"exec_inputs,omitempty"` + // Gas limit for execution program execution + ExecGasLimit uint64 `protobuf:"varint,6,opt,name=exec_gas_limit,json=execGasLimit,proto3" json:"exec_gas_limit,omitempty"` + // Hex-encoded ID (hash) of the tally program + TallyProgramId string `protobuf:"bytes,7,opt,name=tally_program_id,json=tallyProgramId,proto3" json:"tally_program_id,omitempty"` + // Inputs for the tally program + TallyInputs []byte `protobuf:"bytes,8,opt,name=tally_inputs,json=tallyInputs,proto3" json:"tally_inputs,omitempty"` + // Gas limit for tally program execution + TallyGasLimit uint64 `protobuf:"varint,9,opt,name=tally_gas_limit,json=tallyGasLimit,proto3" json:"tally_gas_limit,omitempty"` + // Number of required data request executors (used as uint16) + ReplicationFactor uint32 `protobuf:"varint,10,opt,name=replication_factor,json=replicationFactor,proto3" json:"replication_factor,omitempty"` + // Specifications for the filter process + ConsensusFilter []byte `protobuf:"bytes,11,opt,name=consensus_filter,json=consensusFilter,proto3" json:"consensus_filter,omitempty"` + // Amount of SEDA tokens per unit gas (used as uint128) + GasPrice cosmossdk_io_math.Int `protobuf:"bytes,12,opt,name=gas_price,json=gasPrice,proto3,customtype=cosmossdk.io/math.Int" json:"gas_price"` + // Public information attached to the data request + Memo []byte `protobuf:"bytes,13,opt,name=memo,proto3" json:"memo,omitempty"` + // Set by SEDA Protocol (e.g. OEV-enabled data requests) + SEDAPayload []byte `protobuf:"bytes,14,opt,name=s_e_d_a_payload,json=sEDAPayload,proto3" json:"s_e_d_a_payload,omitempty"` + // Set by the relayer + PaybackAddress []byte `protobuf:"bytes,15,opt,name=payback_address,json=paybackAddress,proto3" json:"payback_address,omitempty"` +} + +func (m *MsgPostDataRequest) Reset() { *m = MsgPostDataRequest{} } +func (m *MsgPostDataRequest) String() string { return proto.CompactTextString(m) } +func (*MsgPostDataRequest) ProtoMessage() {} +func (*MsgPostDataRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{4} +} +func (m *MsgPostDataRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPostDataRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPostDataRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPostDataRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPostDataRequest.Merge(m, src) +} +func (m *MsgPostDataRequest) XXX_Size() int { + return m.Size() +} +func (m *MsgPostDataRequest) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPostDataRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPostDataRequest proto.InternalMessageInfo + +func (m *MsgPostDataRequest) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgPostDataRequest) GetFunds() types.Coin { + if m != nil { + return m.Funds + } + return types.Coin{} +} + +func (m *MsgPostDataRequest) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +func (m *MsgPostDataRequest) GetExecProgramId() string { + if m != nil { + return m.ExecProgramId + } + return "" +} + +func (m *MsgPostDataRequest) GetExecInputs() []byte { + if m != nil { + return m.ExecInputs + } + return nil +} + +func (m *MsgPostDataRequest) GetExecGasLimit() uint64 { + if m != nil { + return m.ExecGasLimit + } + return 0 +} + +func (m *MsgPostDataRequest) GetTallyProgramId() string { + if m != nil { + return m.TallyProgramId + } + return "" +} + +func (m *MsgPostDataRequest) GetTallyInputs() []byte { + if m != nil { + return m.TallyInputs + } + return nil +} + +func (m *MsgPostDataRequest) GetTallyGasLimit() uint64 { + if m != nil { + return m.TallyGasLimit + } + return 0 +} + +func (m *MsgPostDataRequest) GetReplicationFactor() uint32 { + if m != nil { + return m.ReplicationFactor + } + return 0 +} + +func (m *MsgPostDataRequest) GetConsensusFilter() []byte { + if m != nil { + return m.ConsensusFilter + } + return nil +} + +func (m *MsgPostDataRequest) GetMemo() []byte { + if m != nil { + return m.Memo + } + return nil +} + +func (m *MsgPostDataRequest) GetSEDAPayload() []byte { + if m != nil { + return m.SEDAPayload + } + return nil +} + +func (m *MsgPostDataRequest) GetPaybackAddress() []byte { + if m != nil { + return m.PaybackAddress + } + return nil +} + +// The response message for the PostDataRequest method. +type MsgPostDataRequestResponse struct { + // DrId is the hex-encoded ID of the data request. + DrId string `protobuf:"bytes,1,opt,name=dr_id,json=drId,proto3" json:"dr_id,omitempty"` + // Height is the block height at which the data request was posted. + Height int64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"` +} + +func (m *MsgPostDataRequestResponse) Reset() { *m = MsgPostDataRequestResponse{} } +func (m *MsgPostDataRequestResponse) String() string { return proto.CompactTextString(m) } +func (*MsgPostDataRequestResponse) ProtoMessage() {} +func (*MsgPostDataRequestResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{5} +} +func (m *MsgPostDataRequestResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgPostDataRequestResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgPostDataRequestResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgPostDataRequestResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgPostDataRequestResponse.Merge(m, src) +} +func (m *MsgPostDataRequestResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgPostDataRequestResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgPostDataRequestResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgPostDataRequestResponse proto.InternalMessageInfo + +func (m *MsgPostDataRequestResponse) GetDrId() string { + if m != nil { + return m.DrId + } + return "" +} + +func (m *MsgPostDataRequestResponse) GetHeight() int64 { + if m != nil { + return m.Height + } + return 0 +} + +// The request message for the Commit method. +type MsgCommit struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + DrId string `protobuf:"bytes,2,opt,name=dr_id,json=drId,proto3" json:"dr_id,omitempty"` + Commit string `protobuf:"bytes,3,opt,name=commit,proto3" json:"commit,omitempty"` + PublicKey string `protobuf:"bytes,4,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + Proof string `protobuf:"bytes,5,opt,name=proof,proto3" json:"proof,omitempty"` +} + +func (m *MsgCommit) Reset() { *m = MsgCommit{} } +func (m *MsgCommit) String() string { return proto.CompactTextString(m) } +func (*MsgCommit) ProtoMessage() {} +func (*MsgCommit) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{6} +} +func (m *MsgCommit) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommit) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommit.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommit) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommit.Merge(m, src) +} +func (m *MsgCommit) XXX_Size() int { + return m.Size() +} +func (m *MsgCommit) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommit.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommit proto.InternalMessageInfo + +func (m *MsgCommit) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgCommit) GetDrId() string { + if m != nil { + return m.DrId + } + return "" +} + +func (m *MsgCommit) GetCommit() string { + if m != nil { + return m.Commit + } + return "" +} + +func (m *MsgCommit) GetPublicKey() string { + if m != nil { + return m.PublicKey + } + return "" +} + +func (m *MsgCommit) GetProof() string { + if m != nil { + return m.Proof + } + return "" +} + +// The response message for the Commit method. +type MsgCommitResponse struct { +} + +func (m *MsgCommitResponse) Reset() { *m = MsgCommitResponse{} } +func (m *MsgCommitResponse) String() string { return proto.CompactTextString(m) } +func (*MsgCommitResponse) ProtoMessage() {} +func (*MsgCommitResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{7} +} +func (m *MsgCommitResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgCommitResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgCommitResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgCommitResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgCommitResponse.Merge(m, src) +} +func (m *MsgCommitResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgCommitResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgCommitResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgCommitResponse proto.InternalMessageInfo + +// The request message for the Reveal method. +type MsgReveal struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + RevealBody *RevealBody `protobuf:"bytes,2,opt,name=reveal_body,json=revealBody,proto3" json:"reveal_body,omitempty"` + PublicKey string `protobuf:"bytes,3,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` + Proof string `protobuf:"bytes,4,opt,name=proof,proto3" json:"proof,omitempty"` + Stderr []string `protobuf:"bytes,5,rep,name=stderr,proto3" json:"stderr,omitempty"` + Stdout []string `protobuf:"bytes,6,rep,name=stdout,proto3" json:"stdout,omitempty"` +} + +func (m *MsgReveal) Reset() { *m = MsgReveal{} } +func (m *MsgReveal) String() string { return proto.CompactTextString(m) } +func (*MsgReveal) ProtoMessage() {} +func (*MsgReveal) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{8} +} +func (m *MsgReveal) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgReveal) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgReveal.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgReveal) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgReveal.Merge(m, src) +} +func (m *MsgReveal) XXX_Size() int { + return m.Size() +} +func (m *MsgReveal) XXX_DiscardUnknown() { + xxx_messageInfo_MsgReveal.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgReveal proto.InternalMessageInfo + +func (m *MsgReveal) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgReveal) GetRevealBody() *RevealBody { + if m != nil { + return m.RevealBody + } + return nil +} + +func (m *MsgReveal) GetPublicKey() string { + if m != nil { + return m.PublicKey + } + return "" +} + +func (m *MsgReveal) GetProof() string { + if m != nil { + return m.Proof + } + return "" +} + +func (m *MsgReveal) GetStderr() []string { + if m != nil { + return m.Stderr + } + return nil +} + +func (m *MsgReveal) GetStdout() []string { + if m != nil { + return m.Stdout + } + return nil +} + +// The response message for the Reveal method. +type MsgRevealResponse struct { +} + +func (m *MsgRevealResponse) Reset() { *m = MsgRevealResponse{} } +func (m *MsgRevealResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRevealResponse) ProtoMessage() {} +func (*MsgRevealResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{9} +} +func (m *MsgRevealResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRevealResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRevealResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRevealResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRevealResponse.Merge(m, src) +} +func (m *MsgRevealResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRevealResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRevealResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRevealResponse proto.InternalMessageInfo + +// The request message for the UpdateParams method. +type MsgUpdateParams struct { + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{10} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// The response message for the UpdateParams method. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_d0c9e88c2cee8ff0, []int{11} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgAddToAllowlist)(nil), "sedachain.core.v1.MsgAddToAllowlist") + proto.RegisterType((*MsgAddToAllowlistResponse)(nil), "sedachain.core.v1.MsgAddToAllowlistResponse") + proto.RegisterType((*MsgStake)(nil), "sedachain.core.v1.MsgStake") + proto.RegisterType((*MsgStakeResponse)(nil), "sedachain.core.v1.MsgStakeResponse") + proto.RegisterType((*MsgPostDataRequest)(nil), "sedachain.core.v1.MsgPostDataRequest") + proto.RegisterType((*MsgPostDataRequestResponse)(nil), "sedachain.core.v1.MsgPostDataRequestResponse") + proto.RegisterType((*MsgCommit)(nil), "sedachain.core.v1.MsgCommit") + proto.RegisterType((*MsgCommitResponse)(nil), "sedachain.core.v1.MsgCommitResponse") + proto.RegisterType((*MsgReveal)(nil), "sedachain.core.v1.MsgReveal") + proto.RegisterType((*MsgRevealResponse)(nil), "sedachain.core.v1.MsgRevealResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "sedachain.core.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sedachain.core.v1.MsgUpdateParamsResponse") +} + +func init() { proto.RegisterFile("sedachain/core/v1/tx.proto", fileDescriptor_d0c9e88c2cee8ff0) } + +var fileDescriptor_d0c9e88c2cee8ff0 = []byte{ + // 1058 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x56, 0x3d, 0x6f, 0x1b, 0x47, + 0x13, 0xd6, 0x59, 0x24, 0x2d, 0x0e, 0x25, 0x52, 0x5a, 0xeb, 0xb5, 0x4f, 0xb4, 0x4d, 0xe9, 0x65, + 0x14, 0x47, 0x11, 0xa2, 0xa3, 0xe5, 0x00, 0x09, 0xa0, 0x22, 0x80, 0x64, 0xc7, 0x01, 0x11, 0x13, + 0x10, 0xce, 0x49, 0x93, 0x22, 0x87, 0xe5, 0xdd, 0xea, 0x78, 0xd0, 0xdd, 0xed, 0x79, 0x77, 0xa9, + 0x88, 0x5d, 0x90, 0x5f, 0x10, 0xa4, 0x4b, 0x9b, 0x2a, 0x45, 0x0a, 0x17, 0xfe, 0x11, 0xae, 0x02, + 0xc3, 0x55, 0x90, 0xc2, 0x08, 0xa4, 0xc2, 0x65, 0xfe, 0x42, 0xb0, 0x1f, 0x3c, 0x89, 0x1f, 0xb2, + 0x15, 0x23, 0x0d, 0xc1, 0x7d, 0xe6, 0xd9, 0x79, 0x66, 0x66, 0x67, 0x76, 0x0f, 0xea, 0x9c, 0x04, + 0xd8, 0xef, 0xe1, 0x28, 0x6d, 0xf9, 0x94, 0x91, 0xd6, 0xd1, 0x76, 0x4b, 0x1c, 0x3b, 0x19, 0xa3, + 0x82, 0xa2, 0xa5, 0xdc, 0xe6, 0x48, 0x9b, 0x73, 0xb4, 0x5d, 0x5f, 0x0e, 0x69, 0x48, 0x95, 0xb5, + 0x25, 0xff, 0x69, 0x62, 0x7d, 0x09, 0x27, 0x51, 0x4a, 0x5b, 0xea, 0xd7, 0x40, 0x2b, 0x3e, 0xe5, + 0x09, 0xe5, 0x9e, 0xe6, 0xea, 0x85, 0x31, 0xdd, 0xd0, 0xab, 0x56, 0xc2, 0x43, 0x29, 0x97, 0xf0, + 0xd0, 0x18, 0x1a, 0xc6, 0xd0, 0xc5, 0x5c, 0x06, 0xd2, 0x25, 0x02, 0x6f, 0xb7, 0x7c, 0x1a, 0xa5, + 0xc6, 0x7e, 0x6b, 0x32, 0x56, 0x15, 0x97, 0xb2, 0x36, 0x9f, 0xc0, 0x52, 0x87, 0x87, 0xbb, 0x41, + 0xf0, 0x15, 0xdd, 0x8d, 0x63, 0xfa, 0x5d, 0x1c, 0x71, 0x81, 0xee, 0x42, 0x89, 0x93, 0x34, 0x20, + 0xcc, 0xb6, 0xd6, 0xac, 0x8d, 0xf2, 0x9e, 0xfd, 0xf2, 0xd9, 0xd6, 0xb2, 0x89, 0x66, 0x37, 0x08, + 0x18, 0xe1, 0xfc, 0xb1, 0x60, 0x51, 0x1a, 0xba, 0x86, 0x87, 0x6e, 0x03, 0x64, 0xfd, 0x6e, 0x1c, + 0xf9, 0xde, 0x21, 0x19, 0xd8, 0x57, 0xe4, 0x2e, 0xb7, 0xac, 0x91, 0x2f, 0xc9, 0x60, 0xa7, 0xf2, + 0xc3, 0xeb, 0xa7, 0x9b, 0x86, 0xdb, 0xbc, 0x09, 0x2b, 0x13, 0x92, 0x2e, 0xe1, 0x19, 0x4d, 0x39, + 0x69, 0xfe, 0x6e, 0xc1, 0x5c, 0x87, 0x87, 0x8f, 0x05, 0x3e, 0x24, 0xff, 0x79, 0x1c, 0x08, 0x41, + 0x21, 0x21, 0x09, 0xb5, 0x67, 0x95, 0x41, 0xfd, 0x47, 0xcb, 0x50, 0xcc, 0x18, 0xa5, 0x07, 0x76, + 0x41, 0x81, 0x7a, 0x81, 0x76, 0xa0, 0xc8, 0x65, 0x0c, 0x76, 0x71, 0xcd, 0xda, 0xa8, 0xdc, 0x5b, + 0x71, 0x8c, 0xac, 0xac, 0xb2, 0x63, 0xaa, 0xec, 0xdc, 0xa7, 0x51, 0xba, 0x57, 0x7e, 0xfe, 0x6a, + 0x75, 0xe6, 0xd7, 0xd7, 0x4f, 0x37, 0x2d, 0x57, 0x6f, 0x19, 0xcd, 0x16, 0xc1, 0xe2, 0x30, 0x9f, + 0x3c, 0xc9, 0x9f, 0x8b, 0x80, 0x3a, 0x3c, 0xdc, 0xa7, 0x5c, 0x3c, 0xc0, 0x02, 0xbb, 0xe4, 0x49, + 0x9f, 0xbc, 0x53, 0xd9, 0x77, 0xa0, 0x78, 0xd0, 0x4f, 0x03, 0xae, 0x32, 0xbd, 0x74, 0x94, 0x6a, + 0x0b, 0xb2, 0xe1, 0xea, 0x11, 0x61, 0x3c, 0xa2, 0xa9, 0x29, 0xc7, 0x70, 0x89, 0xee, 0x40, 0x8d, + 0x1c, 0x13, 0x5f, 0x76, 0x61, 0xc8, 0x70, 0xe2, 0x45, 0x81, 0xa9, 0xcd, 0x82, 0x84, 0xf7, 0x35, + 0xda, 0x0e, 0xd0, 0x2a, 0x54, 0x14, 0x2f, 0x4a, 0xb3, 0xbe, 0xe0, 0xaa, 0x52, 0xf3, 0x2e, 0x48, + 0xa8, 0xad, 0x10, 0xb4, 0x0e, 0x55, 0x45, 0x08, 0x31, 0xf7, 0xe2, 0x28, 0x89, 0x84, 0x5d, 0x5a, + 0xb3, 0x36, 0x0a, 0xee, 0xbc, 0x44, 0xbf, 0xc0, 0xfc, 0x91, 0xc4, 0xd0, 0x06, 0x2c, 0x0a, 0x1c, + 0xc7, 0x83, 0xf3, 0x7a, 0x57, 0x95, 0x5e, 0x55, 0xe1, 0x67, 0x82, 0xff, 0x87, 0x79, 0xcd, 0x34, + 0x8a, 0x73, 0x4a, 0xb1, 0xa2, 0x30, 0x23, 0x79, 0x07, 0x6a, 0x9a, 0x72, 0xa6, 0x59, 0x56, 0x9a, + 0x0b, 0x0a, 0xce, 0x45, 0xb7, 0x00, 0x31, 0x92, 0xc5, 0x91, 0x8f, 0x45, 0x44, 0x53, 0xef, 0x00, + 0xfb, 0x82, 0x32, 0x1b, 0xd6, 0xac, 0x8d, 0x05, 0x77, 0xe9, 0x9c, 0xe5, 0xa1, 0x32, 0xa0, 0x0f, + 0x61, 0xd1, 0x97, 0x47, 0x97, 0xf2, 0x3e, 0xf7, 0x0e, 0xa2, 0x58, 0x10, 0x66, 0x57, 0x94, 0x7a, + 0x2d, 0xc7, 0x1f, 0x2a, 0x18, 0x75, 0xa0, 0x2c, 0xb5, 0x33, 0x16, 0xf9, 0xc4, 0x9e, 0x57, 0x07, + 0x79, 0x57, 0x16, 0xff, 0xcf, 0x57, 0xab, 0xff, 0xd3, 0xc7, 0xc3, 0x83, 0x43, 0x27, 0xa2, 0xad, + 0x04, 0x8b, 0x9e, 0xd3, 0x4e, 0xc5, 0xcb, 0x67, 0x5b, 0x60, 0xce, 0xad, 0x9d, 0x0a, 0x7d, 0x46, + 0x73, 0x21, 0xe6, 0xfb, 0xd2, 0x43, 0xde, 0xb2, 0x0b, 0x4a, 0x4d, 0xb7, 0xec, 0x3a, 0xd4, 0xb8, + 0x47, 0xbc, 0xc0, 0xc3, 0x5e, 0x86, 0x07, 0x31, 0xc5, 0x81, 0x5d, 0xd5, 0xa5, 0xe0, 0x9f, 0x3f, + 0xd8, 0xdd, 0xd7, 0x10, 0xfa, 0x00, 0x6a, 0x19, 0x1e, 0x74, 0xb1, 0x7f, 0xe8, 0x61, 0xdd, 0x3d, + 0x76, 0x4d, 0xb1, 0xaa, 0x06, 0x36, 0x3d, 0x35, 0xda, 0xaf, 0x6d, 0xa8, 0x4f, 0xb6, 0xe6, 0xb0, + 0x73, 0xd1, 0x35, 0x28, 0x06, 0x4c, 0x1e, 0x90, 0xa5, 0x27, 0x28, 0x60, 0xed, 0x00, 0x5d, 0x87, + 0x52, 0x8f, 0x44, 0x61, 0x4f, 0xa8, 0x36, 0x9c, 0x75, 0xcd, 0xaa, 0xf9, 0x9b, 0x05, 0xe5, 0x0e, + 0x0f, 0xef, 0xd3, 0x44, 0x56, 0xfc, 0xdf, 0x77, 0x77, 0x2e, 0x76, 0x65, 0x54, 0xcc, 0x57, 0x0e, + 0x4d, 0xd7, 0x9a, 0xd5, 0xd8, 0xe4, 0x17, 0xc6, 0x27, 0x3f, 0x9f, 0xf2, 0xe2, 0xb9, 0x29, 0x1f, + 0xcd, 0xfc, 0x9a, 0xba, 0x0a, 0x75, 0xb4, 0xf9, 0xa8, 0xfe, 0xad, 0x73, 0x70, 0xc9, 0x11, 0xc1, + 0xf1, 0x3b, 0xe4, 0xf0, 0x19, 0x54, 0x98, 0xda, 0xeb, 0x75, 0x69, 0x30, 0x30, 0x73, 0x7a, 0xdb, + 0x99, 0x78, 0x23, 0x1c, 0xad, 0xb0, 0x47, 0x83, 0x81, 0x0b, 0x2c, 0xff, 0x3f, 0x96, 0xd6, 0xec, + 0x85, 0x69, 0x8d, 0x5c, 0x5e, 0xd7, 0xa1, 0xc4, 0x45, 0x40, 0x18, 0xb3, 0x8b, 0x6b, 0xb3, 0xb2, + 0x46, 0x7a, 0x65, 0x70, 0xda, 0x97, 0x73, 0x38, 0xc4, 0x69, 0x5f, 0x4c, 0x2b, 0x83, 0x0e, 0x27, + 0x2f, 0xc3, 0x4f, 0x16, 0xd4, 0x3a, 0x3c, 0xfc, 0x3a, 0x0b, 0xb0, 0x20, 0xfb, 0x98, 0xe1, 0x84, + 0xa3, 0x4f, 0xa0, 0x8c, 0xfb, 0xa2, 0x47, 0x59, 0x24, 0x06, 0x6f, 0xad, 0xc7, 0x19, 0x15, 0x7d, + 0x0a, 0xa5, 0x4c, 0x79, 0xc8, 0x6f, 0xad, 0xc9, 0x6a, 0x68, 0x89, 0xbd, 0x82, 0x1c, 0x1c, 0xd7, + 0xd0, 0x77, 0xaa, 0x32, 0xcc, 0x33, 0x47, 0xcd, 0x15, 0xb8, 0x31, 0x16, 0xd3, 0x30, 0xde, 0x7b, + 0xbf, 0x14, 0x60, 0xb6, 0xc3, 0x43, 0x14, 0x40, 0x75, 0xec, 0x6d, 0x5b, 0x9f, 0xa2, 0x36, 0xf1, + 0x1c, 0xd5, 0x3f, 0xba, 0x0c, 0x2b, 0x9f, 0x8a, 0x36, 0x14, 0xf5, 0x83, 0x75, 0x73, 0xfa, 0x36, + 0x65, 0xac, 0xbf, 0xf7, 0x06, 0x63, 0xee, 0x2a, 0x84, 0xda, 0xf8, 0xb3, 0xf0, 0xfe, 0xf4, 0x7d, + 0x63, 0xb4, 0xfa, 0xd6, 0xa5, 0x68, 0xb9, 0xd0, 0x23, 0x28, 0x99, 0xc1, 0xbc, 0x35, 0x7d, 0xa3, + 0xb6, 0xd6, 0xd7, 0xdf, 0x64, 0x3d, 0xef, 0xcd, 0x8c, 0xc8, 0x05, 0xde, 0xb4, 0xf5, 0x22, 0x6f, + 0xa3, 0xdd, 0x86, 0xbe, 0x85, 0xf9, 0x91, 0x4e, 0x6b, 0x4e, 0xdf, 0x75, 0x9e, 0x53, 0xdf, 0x7c, + 0x3b, 0x67, 0xe8, 0xbf, 0x5e, 0xfc, 0x5e, 0x5e, 0xb2, 0x7b, 0xed, 0xe7, 0x27, 0x0d, 0xeb, 0xc5, + 0x49, 0xc3, 0xfa, 0xeb, 0xa4, 0x61, 0xfd, 0x78, 0xda, 0x98, 0x79, 0x71, 0xda, 0x98, 0xf9, 0xe3, + 0xb4, 0x31, 0xf3, 0x4d, 0x2b, 0x8c, 0x44, 0xaf, 0xdf, 0x75, 0x7c, 0x9a, 0xb4, 0xa4, 0x5b, 0xf5, + 0xad, 0xe4, 0xd3, 0x58, 0x2d, 0xb6, 0xf4, 0xc7, 0xd4, 0xb1, 0xfe, 0x9c, 0x12, 0x83, 0x8c, 0xf0, + 0x6e, 0x49, 0x31, 0x3e, 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x2d, 0x10, 0x93, 0x19, 0x0a, + 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // AddToAllowlist adds a new address to the allowlist. + AddToAllowlist(ctx context.Context, in *MsgAddToAllowlist, opts ...grpc.CallOption) (*MsgAddToAllowlistResponse, error) + // Stake adds a stake to the executor identity. + Stake(ctx context.Context, in *MsgStake, opts ...grpc.CallOption) (*MsgStakeResponse, error) + // PostDataRequest posts a data request. + PostDataRequest(ctx context.Context, in *MsgPostDataRequest, opts ...grpc.CallOption) (*MsgPostDataRequestResponse, error) + // Commit makes a commitment to reveal a data result. + Commit(ctx context.Context, in *MsgCommit, opts ...grpc.CallOption) (*MsgCommitResponse, error) + // Reveal reveals a data result. + Reveal(ctx context.Context, in *MsgReveal, opts ...grpc.CallOption) (*MsgRevealResponse, error) + // UpdateParams updates the module's parameters. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) AddToAllowlist(ctx context.Context, in *MsgAddToAllowlist, opts ...grpc.CallOption) (*MsgAddToAllowlistResponse, error) { + out := new(MsgAddToAllowlistResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/AddToAllowlist", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Stake(ctx context.Context, in *MsgStake, opts ...grpc.CallOption) (*MsgStakeResponse, error) { + out := new(MsgStakeResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/Stake", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) PostDataRequest(ctx context.Context, in *MsgPostDataRequest, opts ...grpc.CallOption) (*MsgPostDataRequestResponse, error) { + out := new(MsgPostDataRequestResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/PostDataRequest", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Commit(ctx context.Context, in *MsgCommit, opts ...grpc.CallOption) (*MsgCommitResponse, error) { + out := new(MsgCommitResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/Commit", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) Reveal(ctx context.Context, in *MsgReveal, opts ...grpc.CallOption) (*MsgRevealResponse, error) { + out := new(MsgRevealResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/Reveal", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/sedachain.core.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // AddToAllowlist adds a new address to the allowlist. + AddToAllowlist(context.Context, *MsgAddToAllowlist) (*MsgAddToAllowlistResponse, error) + // Stake adds a stake to the executor identity. + Stake(context.Context, *MsgStake) (*MsgStakeResponse, error) + // PostDataRequest posts a data request. + PostDataRequest(context.Context, *MsgPostDataRequest) (*MsgPostDataRequestResponse, error) + // Commit makes a commitment to reveal a data result. + Commit(context.Context, *MsgCommit) (*MsgCommitResponse, error) + // Reveal reveals a data result. + Reveal(context.Context, *MsgReveal) (*MsgRevealResponse, error) + // UpdateParams updates the module's parameters. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) AddToAllowlist(ctx context.Context, req *MsgAddToAllowlist) (*MsgAddToAllowlistResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddToAllowlist not implemented") +} +func (*UnimplementedMsgServer) Stake(ctx context.Context, req *MsgStake) (*MsgStakeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Stake not implemented") +} +func (*UnimplementedMsgServer) PostDataRequest(ctx context.Context, req *MsgPostDataRequest) (*MsgPostDataRequestResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method PostDataRequest not implemented") +} +func (*UnimplementedMsgServer) Commit(ctx context.Context, req *MsgCommit) (*MsgCommitResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Commit not implemented") +} +func (*UnimplementedMsgServer) Reveal(ctx context.Context, req *MsgReveal) (*MsgRevealResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Reveal not implemented") +} +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_AddToAllowlist_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddToAllowlist) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddToAllowlist(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/AddToAllowlist", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddToAllowlist(ctx, req.(*MsgAddToAllowlist)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Stake_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgStake) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Stake(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/Stake", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Stake(ctx, req.(*MsgStake)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_PostDataRequest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgPostDataRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).PostDataRequest(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/PostDataRequest", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).PostDataRequest(ctx, req.(*MsgPostDataRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Commit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgCommit) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Commit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/Commit", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Commit(ctx, req.(*MsgCommit)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_Reveal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgReveal) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).Reveal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/Reveal", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).Reveal(ctx, req.(*MsgReveal)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sedachain.core.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "sedachain.core.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddToAllowlist", + Handler: _Msg_AddToAllowlist_Handler, + }, + { + MethodName: "Stake", + Handler: _Msg_Stake_Handler, + }, + { + MethodName: "PostDataRequest", + Handler: _Msg_PostDataRequest_Handler, + }, + { + MethodName: "Commit", + Handler: _Msg_Commit_Handler, + }, + { + MethodName: "Reveal", + Handler: _Msg_Reveal_Handler, + }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sedachain/core/v1/tx.proto", +} + +func (m *MsgAddToAllowlist) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddToAllowlist) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddToAllowlist) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgAddToAllowlistResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddToAllowlistResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddToAllowlistResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgStake) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStake) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStake) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Stake.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x2a + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x22 + } + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintTx(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x1a + } + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgStakeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgStakeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgStakeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgPostDataRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPostDataRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPostDataRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.PaybackAddress) > 0 { + i -= len(m.PaybackAddress) + copy(dAtA[i:], m.PaybackAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.PaybackAddress))) + i-- + dAtA[i] = 0x7a + } + if len(m.SEDAPayload) > 0 { + i -= len(m.SEDAPayload) + copy(dAtA[i:], m.SEDAPayload) + i = encodeVarintTx(dAtA, i, uint64(len(m.SEDAPayload))) + i-- + dAtA[i] = 0x72 + } + if len(m.Memo) > 0 { + i -= len(m.Memo) + copy(dAtA[i:], m.Memo) + i = encodeVarintTx(dAtA, i, uint64(len(m.Memo))) + i-- + dAtA[i] = 0x6a + } + { + size := m.GasPrice.Size() + i -= size + if _, err := m.GasPrice.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x62 + if len(m.ConsensusFilter) > 0 { + i -= len(m.ConsensusFilter) + copy(dAtA[i:], m.ConsensusFilter) + i = encodeVarintTx(dAtA, i, uint64(len(m.ConsensusFilter))) + i-- + dAtA[i] = 0x5a + } + if m.ReplicationFactor != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ReplicationFactor)) + i-- + dAtA[i] = 0x50 + } + if m.TallyGasLimit != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.TallyGasLimit)) + i-- + dAtA[i] = 0x48 + } + if len(m.TallyInputs) > 0 { + i -= len(m.TallyInputs) + copy(dAtA[i:], m.TallyInputs) + i = encodeVarintTx(dAtA, i, uint64(len(m.TallyInputs))) + i-- + dAtA[i] = 0x42 + } + if len(m.TallyProgramId) > 0 { + i -= len(m.TallyProgramId) + copy(dAtA[i:], m.TallyProgramId) + i = encodeVarintTx(dAtA, i, uint64(len(m.TallyProgramId))) + i-- + dAtA[i] = 0x3a + } + if m.ExecGasLimit != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.ExecGasLimit)) + i-- + dAtA[i] = 0x30 + } + if len(m.ExecInputs) > 0 { + i -= len(m.ExecInputs) + copy(dAtA[i:], m.ExecInputs) + i = encodeVarintTx(dAtA, i, uint64(len(m.ExecInputs))) + i-- + dAtA[i] = 0x2a + } + if len(m.ExecProgramId) > 0 { + i -= len(m.ExecProgramId) + copy(dAtA[i:], m.ExecProgramId) + i = encodeVarintTx(dAtA, i, uint64(len(m.ExecProgramId))) + i-- + dAtA[i] = 0x22 + } + if len(m.Version) > 0 { + i -= len(m.Version) + copy(dAtA[i:], m.Version) + i = encodeVarintTx(dAtA, i, uint64(len(m.Version))) + i-- + dAtA[i] = 0x1a + } + { + size, err := m.Funds.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgPostDataRequestResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgPostDataRequestResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgPostDataRequestResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Height != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Height)) + i-- + dAtA[i] = 0x10 + } + if len(m.DrId) > 0 { + i -= len(m.DrId) + copy(dAtA[i:], m.DrId) + i = encodeVarintTx(dAtA, i, uint64(len(m.DrId))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCommit) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommit) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommit) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x2a + } + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0x22 + } + if len(m.Commit) > 0 { + i -= len(m.Commit) + copy(dAtA[i:], m.Commit) + i = encodeVarintTx(dAtA, i, uint64(len(m.Commit))) + i-- + dAtA[i] = 0x1a + } + if len(m.DrId) > 0 { + i -= len(m.DrId) + copy(dAtA[i:], m.DrId) + i = encodeVarintTx(dAtA, i, uint64(len(m.DrId))) + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgCommitResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgCommitResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgCommitResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgReveal) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgReveal) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgReveal) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Stdout) > 0 { + for iNdEx := len(m.Stdout) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Stdout[iNdEx]) + copy(dAtA[i:], m.Stdout[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Stdout[iNdEx]))) + i-- + dAtA[i] = 0x32 + } + } + if len(m.Stderr) > 0 { + for iNdEx := len(m.Stderr) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Stderr[iNdEx]) + copy(dAtA[i:], m.Stderr[iNdEx]) + i = encodeVarintTx(dAtA, i, uint64(len(m.Stderr[iNdEx]))) + i-- + dAtA[i] = 0x2a + } + } + if len(m.Proof) > 0 { + i -= len(m.Proof) + copy(dAtA[i:], m.Proof) + i = encodeVarintTx(dAtA, i, uint64(len(m.Proof))) + i-- + dAtA[i] = 0x22 + } + if len(m.PublicKey) > 0 { + i -= len(m.PublicKey) + copy(dAtA[i:], m.PublicKey) + i = encodeVarintTx(dAtA, i, uint64(len(m.PublicKey))) + i-- + dAtA[i] = 0x1a + } + if m.RevealBody != nil { + { + size, err := m.RevealBody.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRevealResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRevealResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRevealResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAddToAllowlist) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAddToAllowlistResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgStake) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Stake.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgStakeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgPostDataRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Funds.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Version) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ExecProgramId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ExecInputs) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.ExecGasLimit != 0 { + n += 1 + sovTx(uint64(m.ExecGasLimit)) + } + l = len(m.TallyProgramId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.TallyInputs) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.TallyGasLimit != 0 { + n += 1 + sovTx(uint64(m.TallyGasLimit)) + } + if m.ReplicationFactor != 0 { + n += 1 + sovTx(uint64(m.ReplicationFactor)) + } + l = len(m.ConsensusFilter) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.GasPrice.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Memo) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.SEDAPayload) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PaybackAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgPostDataRequestResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.DrId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Height != 0 { + n += 1 + sovTx(uint64(m.Height)) + } + return n +} + +func (m *MsgCommit) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.DrId) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Commit) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgCommitResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgReveal) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.RevealBody != nil { + l = m.RevealBody.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.PublicKey) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Proof) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.Stderr) > 0 { + for _, s := range m.Stderr { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.Stdout) > 0 { + for _, s := range m.Stdout { + l = len(s) + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *MsgRevealResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAddToAllowlist) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddToAllowlist: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddToAllowlist: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddToAllowlistResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddToAllowlistResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddToAllowlistResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgStake) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStake: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStake: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Memo = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Stake", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Stake.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgStakeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgStakeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgStakeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPostDataRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPostDataRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPostDataRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Funds", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Funds.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Version = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecProgramId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExecProgramId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecInputs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ExecInputs = append(m.ExecInputs[:0], dAtA[iNdEx:postIndex]...) + if m.ExecInputs == nil { + m.ExecInputs = []byte{} + } + iNdEx = postIndex + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ExecGasLimit", wireType) + } + m.ExecGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ExecGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyProgramId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TallyProgramId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyInputs", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.TallyInputs = append(m.TallyInputs[:0], dAtA[iNdEx:postIndex]...) + if m.TallyInputs == nil { + m.TallyInputs = []byte{} + } + iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field TallyGasLimit", wireType) + } + m.TallyGasLimit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.TallyGasLimit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ReplicationFactor", wireType) + } + m.ReplicationFactor = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ReplicationFactor |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ConsensusFilter", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ConsensusFilter = append(m.ConsensusFilter[:0], dAtA[iNdEx:postIndex]...) + if m.ConsensusFilter == nil { + m.ConsensusFilter = []byte{} + } + iNdEx = postIndex + case 12: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field GasPrice", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.GasPrice.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 13: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Memo", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Memo = append(m.Memo[:0], dAtA[iNdEx:postIndex]...) + if m.Memo == nil { + m.Memo = []byte{} + } + iNdEx = postIndex + case 14: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SEDAPayload", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SEDAPayload = append(m.SEDAPayload[:0], dAtA[iNdEx:postIndex]...) + if m.SEDAPayload == nil { + m.SEDAPayload = []byte{} + } + iNdEx = postIndex + case 15: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PaybackAddress", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PaybackAddress = append(m.PaybackAddress[:0], dAtA[iNdEx:postIndex]...) + if m.PaybackAddress == nil { + m.PaybackAddress = []byte{} + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgPostDataRequestResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgPostDataRequestResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgPostDataRequestResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DrId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Height", wireType) + } + m.Height = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Height |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCommit) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommit: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommit: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field DrId", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DrId = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Commit", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Commit = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgCommitResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgCommitResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgCommitResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgReveal) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgReveal: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgReveal: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RevealBody", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.RevealBody == nil { + m.RevealBody = &RevealBody{} + } + if err := m.RevealBody.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PublicKey", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PublicKey = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Proof", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Proof = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Stderr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Stderr = append(m.Stderr, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Stdout", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Stdout = append(m.Stdout, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRevealResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRevealResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRevealResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/core/types/types.go b/x/core/types/types.go new file mode 100644 index 00000000..3d0b1d8a --- /dev/null +++ b/x/core/types/types.go @@ -0,0 +1,118 @@ +package types + +import ( + "encoding/json" + + "cosmossdk.io/math" + + "github.com/sedaprotocol/seda-wasm-vm/tallyvm/v3" +) + +var _ HashSortable = Reveal{} + +type Reveal struct { + Executor string // executor ID (hex-encoded public key) + RevealBody +} + +func (r Reveal) GetSortKey() []byte { + return []byte(r.Executor) +} + +func (u *RevealBody) MarshalJSON() ([]byte, error) { + type Alias RevealBody + return json.Marshal(&struct { + Reveal []int `json:"reveal"` + *Alias + }{ + Reveal: bytesToIntSlice(u.Reveal), + Alias: (*Alias)(u), + }) +} + +func bytesToIntSlice(bytes []byte) []int { + intSlice := make([]int, len(bytes)) + for i, b := range bytes { + intSlice[i] = int(b) + } + return intSlice +} + +type VMResult struct { + Stdout []string + Stderr []string + Result []byte + GasUsed uint64 + ExitCode uint32 + ExitMessage string +} + +// MapVMResult maps a tallyvm.VmResult to a VmResult, taking care of checking the result pointer +// and setting the exit message if the result is empty. This allows us to display the exit message +// to the end user. +func MapVMResult(vmRes tallyvm.VmResult) VMResult { + result := VMResult{ + //nolint:gosec // G115: We shouldn't get negative exit code anyway. + ExitCode: uint32(vmRes.ExitInfo.ExitCode), + ExitMessage: vmRes.ExitInfo.ExitMessage, + Stdout: vmRes.Stdout, + Stderr: vmRes.Stderr, + GasUsed: vmRes.GasUsed, + } + + if vmRes.Result == nil || (vmRes.ResultLen == 0 && vmRes.ExitInfo.ExitCode != 0) { + result.Result = []byte(vmRes.ExitInfo.ExitMessage) + } else if vmRes.Result != nil { + result.Result = *vmRes.Result + } + + return result +} + +type Distribution struct { + Burn *DistributionBurn `json:"burn,omitempty"` + ExecutorReward *DistributionExecutorReward `json:"executor_reward,omitempty"` + DataProxyReward *DistributionDataProxyReward `json:"data_proxy_reward,omitempty"` +} + +type DistributionBurn struct { + Amount math.Int `json:"amount"` +} + +type DistributionDataProxyReward struct { + PayoutAddress string `json:"payout_address"` + Amount math.Int `json:"amount"` + // The public key of the data proxy as a hex string + PublicKey string `json:"public_key"` +} + +type DistributionExecutorReward struct { + Amount math.Int `json:"amount"` + // The public key of the executor as a hex string + Identity string `json:"identity"` +} + +func NewBurn(amount, gasPrice math.Int) Distribution { + return Distribution{ + Burn: &DistributionBurn{Amount: amount.Mul(gasPrice)}, + } +} + +func NewDataProxyReward(pubkey, payoutAddr string, amount, gasPrice math.Int) Distribution { + return Distribution{ + DataProxyReward: &DistributionDataProxyReward{ + PayoutAddress: payoutAddr, + Amount: amount.Mul(gasPrice), + PublicKey: pubkey, + }, + } +} + +func NewExecutorReward(identity string, amount, gasPrice math.Int) Distribution { + return Distribution{ + ExecutorReward: &DistributionExecutorReward{ + Identity: identity, + Amount: amount.Mul(gasPrice), + }, + } +} diff --git a/x/tally/types/vm_exit_codes.go b/x/core/types/vm_exit_codes.go similarity index 100% rename from x/tally/types/vm_exit_codes.go rename to x/core/types/vm_exit_codes.go diff --git a/x/data-proxy/keeper/msg_server.go b/x/data-proxy/keeper/msg_server.go index f4e87c50..22e58e07 100644 --- a/x/data-proxy/keeper/msg_server.go +++ b/x/data-proxy/keeper/msg_server.go @@ -252,7 +252,7 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", msg.Authority) } if m.GetAuthority() != msg.Authority { - return nil, sdkerrors.ErrorInvalidSigner.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) + return nil, sdkerrors.ErrUnauthorized.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) } if err := msg.Params.Validate(); err != nil { diff --git a/x/data-proxy/keeper/msg_server_test.go b/x/data-proxy/keeper/msg_server_test.go index 879a29c7..752511de 100644 --- a/x/data-proxy/keeper/msg_server_test.go +++ b/x/data-proxy/keeper/msg_server_test.go @@ -611,7 +611,7 @@ func (s *KeeperTestSuite) TestMsgServer_UpdateParamsErrors() { MinFeeUpdateDelay: 8000, }, }, - wantErr: sdkerrors.ErrorInvalidSigner, + wantErr: sdkerrors.ErrUnauthorized, }, } diff --git a/x/data-proxy/types/proxy_config.go b/x/data-proxy/types/proxy_config.go index e2a59666..c29c54e5 100644 --- a/x/data-proxy/types/proxy_config.go +++ b/x/data-proxy/types/proxy_config.go @@ -1,6 +1,8 @@ package types -import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) const ( MaxMemoLength = 3000 diff --git a/x/pubkey/keeper/msg_server.go b/x/pubkey/keeper/msg_server.go index 9de06474..fcc6e4a2 100644 --- a/x/pubkey/keeper/msg_server.go +++ b/x/pubkey/keeper/msg_server.go @@ -84,7 +84,7 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", msg.Authority) } if m.GetAuthority() != msg.Authority { - return nil, sdkerrors.ErrorInvalidSigner.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) + return nil, sdkerrors.ErrUnauthorized.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) } if err := msg.Params.Validate(); err != nil { diff --git a/x/tally/keeper/benchmark_endblock_test.go b/x/tally/keeper/benchmark_endblock_test.go deleted file mode 100644 index 59a7b81b..00000000 --- a/x/tally/keeper/benchmark_endblock_test.go +++ /dev/null @@ -1,80 +0,0 @@ -package keeper_test - -import ( - "encoding/base64" - "fmt" - "testing" - - "github.com/stretchr/testify/require" - "golang.org/x/exp/rand" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/testutil/testwasms" - "github.com/sedaprotocol/seda-chain/x/tally/types" -) - -func BenchmarkDataRequestFlow(b *testing.B) { - f := initFixture(b) - - proxyPubKeys := []string{"03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"} - err := f.SetDataProxyConfig(proxyPubKeys[0], "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f", sdk.NewCoin(bondDenom, math.NewInt(1000000000000000000))) - require.NoError(b, err) - - params := types.DefaultParams() - params.MaxTalliesPerBlock = 1000 - f.tallyKeeper.SetParams(f.Context(), params) - - for i := 0; i < b.N; i++ { - b.StopTimer() - for j := 0; j < 1000; j++ { - f.executeDataRequestFlow( - b, nil, nil, - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - proxyPubKeys: proxyPubKeys, - gasUsed: 150000000000000000, - }) - } - - b.StartTimer() - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(b, err) - - f.AddBlock() - } -} - -func BenchmarkBigTallyPrograms(b *testing.B) { - f := initFixture(b) - - params := types.DefaultParams() - params.MaxTalliesPerBlock = 1000 - f.tallyKeeper.SetParams(f.Context(), params) - - for i := 0; i < b.N; i++ { - b.StopTimer() - for j := 0; j < 1000; j++ { - f.executeDataRequestFlow( - b, nil, testwasms.BigWasm(), - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%x", rand.Int63()))), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - gasUsed: 150000000000000000, - }) - } - - b.StartTimer() - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(b, err) - - f.AddBlock() - } -} diff --git a/x/tally/keeper/endblock_fuzz_test.go b/x/tally/keeper/endblock_fuzz_test.go deleted file mode 100644 index 74120850..00000000 --- a/x/tally/keeper/endblock_fuzz_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package keeper_test - -import ( - "encoding/base64" - "encoding/hex" - "encoding/json" - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/testutil" - "github.com/sedaprotocol/seda-chain/testutil/testwasms" - "github.com/sedaprotocol/seda-chain/x/tally/types" - wasmstoragetypes "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" -) - -func getRandomBytes(length int) []byte { - bytes := make([]byte, length) - rand.Read(bytes) - return bytes -} - -type fuzzCommitReveal struct { - requestHeight uint64 - requestMemo string // base64-encoded - reveal string // base64-encoded - exitCode byte - gasUsed uint64 - proxyPubKeys []string -} - -func FuzzEndBlock(f *testing.F) { - fixture := initFixture(f) - - defaultParams := types.DefaultParams() - err := fixture.tallyKeeper.SetParams(fixture.Context(), defaultParams) - require.NoError(f, err) - - f.Fuzz(func(t *testing.T, reveal, proxyPubKey []byte, exitCode byte, requestHeight, gasUsed uint64) { - sim := fuzzCommitReveal{ - requestHeight: requestHeight, - requestMemo: base64.StdEncoding.EncodeToString(getRandomBytes(10)), - reveal: base64.StdEncoding.EncodeToString(reveal), - exitCode: exitCode, - gasUsed: gasUsed, - proxyPubKeys: []string{hex.EncodeToString(proxyPubKey)}, - } - - drID, _ := fixture.fuzzCommitRevealDataRequest(t, sim, 4, false) - - err = fixture.tallyKeeper.EndBlock(fixture.Context()) - require.NoError(t, err) - require.NotContains(t, fixture.logBuf.String(), "ERR") - - _, err := fixture.batchingKeeper.GetLatestDataResult(fixture.Context(), drID) - require.NoError(t, err) - }) -} - -// fuzzCommitRevealDataRequest simulates stakers committing and revealing -// for a data request. It returns the data request ID. -func (f *fixture) fuzzCommitRevealDataRequest(t *testing.T, fuzz fuzzCommitReveal, replicationFactor int, timeout bool) (string, []staker) { - stakers := f.addStakers(t, 5) - - // Upload data request and tally oracle programs. - execProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm(), f.Context().BlockTime()) - err := f.wasmStorageKeeper.OracleProgram.Set(f.Context(), execProgram.Hash, execProgram) - require.NoError(t, err) - - tallyProgram := wasmstoragetypes.NewOracleProgram(testwasms.SampleTallyWasm2(), f.Context().BlockTime()) - err = f.wasmStorageKeeper.OracleProgram.Set(f.Context(), tallyProgram.Hash, tallyProgram) - require.NoError(t, err) - - // Post a data request. - amount, ok := math.NewIntFromString("200600000000000000000") - require.True(t, ok) - resJSON, err := f.contractKeeper.Execute( - f.Context(), - f.coreContractAddr, - f.deployer, - testutil.PostDataRequestMsg(execProgram.Hash, tallyProgram.Hash, fuzz.requestMemo, replicationFactor), - sdk.NewCoins(sdk.NewCoin(bondDenom, amount)), - ) - require.NoError(t, err) - - type PostDataRequestResponse struct { - DrID string `json:"dr_id"` - Height uint64 `json:"height"` - } - var res PostDataRequestResponse - err = json.Unmarshal(resJSON, &res) - require.NoError(t, err) - drID := res.DrID - - // The stakers commit and reveal. - revealBody := types.RevealBody{ - RequestID: drID, - RequestBlockHeight: fuzz.requestHeight, - Reveal: fuzz.reveal, - GasUsed: fuzz.gasUsed, - ExitCode: fuzz.exitCode, - ProxyPubKeys: []string{}, - } - - var revealMsgs [][]byte - var commitments []string - var revealProofs []string - for i := 0; i < replicationFactor; i++ { - revealMsg, commitment, revealProof, err := f.createRevealMsg(stakers[i], revealBody) - require.NoError(t, err) - - commitProof, err := f.generateCommitProof(stakers[i].key, drID, commitment, res.Height) - require.NoError(t, err) - - commitMsg := testutil.CommitMsg(drID, commitment, stakers[i].pubKey, commitProof, 0) - - err = f.executeCommitReveal(stakers[i].address, commitMsg, 500000) - require.NoError(t, err) - - revealMsgs = append(revealMsgs, revealMsg) - commitments = append(commitments, commitment) - revealProofs = append(revealProofs, revealProof) - } - - for i := 0; i < len(revealMsgs); i++ { - msg := testutil.RevealMsg( - revealBody.RequestID, - revealBody.Reveal, - stakers[i].pubKey, - revealProofs[i], - revealBody.ProxyPubKeys, - revealBody.ExitCode, - revealBody.RequestBlockHeight, - revealBody.GasUsed, - ) - - err = f.executeCommitReveal(stakers[i].address, msg, 500000) - require.NoError(t, err) - } - - if timeout { - timeoutBlocks := defaultCommitTimeoutBlocks - if len(revealMsgs) > 0 { - timeoutBlocks = defaultRevealTimeoutBlocks - } - - for range timeoutBlocks { - f.AddBlock() - } - } - - return res.DrID, stakers -} diff --git a/x/tally/keeper/endblock_test.go b/x/tally/keeper/endblock_test.go deleted file mode 100644 index 7060fd53..00000000 --- a/x/tally/keeper/endblock_test.go +++ /dev/null @@ -1,421 +0,0 @@ -package keeper_test - -import ( - "encoding/base64" - "fmt" - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "cosmossdk.io/math" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/testutil/testwasms" - batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" - tallykeeper "github.com/sedaprotocol/seda-chain/x/tally/keeper" - "github.com/sedaprotocol/seda-chain/x/tally/types" -) - -func TestEndBlock(t *testing.T) { - f := initFixture(t) - - tests := []struct { - name string - memo string - replicationFactor int - numCommits int - numReveals int - timeout bool - expExitCode uint32 - }{ - { - name: "full single commit-reveal", - memo: base64.StdEncoding.EncodeToString([]byte("memo0")), - replicationFactor: 1, - numCommits: 1, - numReveals: 1, - timeout: false, - expExitCode: 0, - }, - { - name: "full 5 commit-reveals", - memo: base64.StdEncoding.EncodeToString([]byte("memo1")), - replicationFactor: 5, - numCommits: 5, - numReveals: 5, - timeout: false, - expExitCode: 0, - }, - { - name: "commit timeout", - memo: base64.StdEncoding.EncodeToString([]byte("memo2")), - replicationFactor: 2, - numCommits: 0, - numReveals: 0, - timeout: true, - expExitCode: types.TallyExitCodeNotEnoughCommits, - }, - { - name: "commit timeout with 1 commit", - memo: base64.StdEncoding.EncodeToString([]byte("memo3")), - replicationFactor: 2, - numCommits: 1, - numReveals: 0, - timeout: true, - expExitCode: types.TallyExitCodeNotEnoughCommits, - }, - { - name: "commit timeout with 2 commits", - memo: base64.StdEncoding.EncodeToString([]byte("memo4")), - replicationFactor: 2, - numCommits: 1, - numReveals: 0, - timeout: true, - expExitCode: types.TallyExitCodeNotEnoughCommits, - }, - { - name: "reveal timeout with no reveals", - memo: base64.StdEncoding.EncodeToString([]byte("memo5")), - replicationFactor: 2, - numCommits: 2, - numReveals: 0, - timeout: true, - expExitCode: types.TallyExitCodeFilterError, - }, - { - name: "reveal timeout with 2 reveals", - memo: base64.StdEncoding.EncodeToString([]byte("memo6")), - replicationFactor: 3, - numCommits: 3, - numReveals: 2, - timeout: true, - expExitCode: 0, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - proxyPubKeys := []string{"03b27f2df0cbdb5cdadff5b4be0c9fda5aa3a59557ef6d0b49b4298ef42c8ce2b0"} - err := f.SetDataProxyConfig(proxyPubKeys[0], "seda1zcds6ws7l0e005h3xrmg5tx0378nyg8gtmn64f", sdk.NewCoin(bondDenom, math.NewInt(1000000000000000000))) - require.NoError(t, err) - - drID := f.executeDataRequestFlow( - t, nil, nil, - tt.replicationFactor, tt.numCommits, tt.numReveals, tt.timeout, - commitRevealConfig{ - requestHeight: 1, - requestMemo: tt.memo, - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - proxyPubKeys: proxyPubKeys, - gasUsed: 150000000000000000, - }) - - beforeBalance := f.bankKeeper.GetBalance(f.Context(), f.stakers[0].address, bondDenom) - posterBeforeBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) - - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - // TODO query get_staker pending_withdrawal and check diff - // Verify the staker did not pay for the transactions - afterBalance := f.bankKeeper.GetBalance(f.Context(), f.stakers[0].address, bondDenom) - diff := afterBalance.Sub(beforeBalance) - require.Equal(t, "0aseda", diff.String()) - - // Verify the poster paid for execution - afterPostBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) - diff = afterPostBalance.Sub(posterBeforeBalance) - require.NotEqual(t, "0aseda", diff.String(), "Poster should have paid for execution") - - dataResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), drID) - require.NoError(t, err) - // TODO map oracle program to exit code - // require.Equal(t, tt.expExitCode, dataResult.ExitCode) - - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Contains(t, dataResults, *dataResult) - }) - } -} - -func TestEndBlock_NoTallyReadyDataRequests(t *testing.T) { - f := initFixture(t) - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - require.NotContains(t, f.logBuf.String(), "ERR") -} - -func TestEndBlock_UpdateMaxResultSize(t *testing.T) { - f := initFixture(t) - - // Set max result size to 1 and verify that the data request fails - params := types.DefaultParams() - params.MaxResultSize = 1 - msg := &types.MsgUpdateParams{ - Authority: f.tallyKeeper.GetAuthority(), - Params: params, - } - - _, err := f.tallyMsgServer.UpdateParams(f.Context(), msg) - require.NoError(t, err) - - drID := f.executeDataRequestFlow( - t, testwasms.SampleTallyWasm(), testwasms.SampleTallyWasm2(), - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte("memo")), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - }) - - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - dataResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), drID) - require.NoError(t, err) - require.NotEqual(t, uint32(0), dataResult.ExitCode) - require.Contains(t, string(dataResult.Result), "Result larger than 1bytes") - - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Contains(t, dataResults, *dataResult) - - // Ensure the new DR gets a unique ID - f.AddBlock() - - // Set max result size to 1024 and verify that the data request succeeds - params.MaxResultSize = 1024 - msg = &types.MsgUpdateParams{ - Authority: f.tallyKeeper.GetAuthority(), - Params: params, - } - - _, err = f.tallyMsgServer.UpdateParams(f.Context(), msg) - require.NoError(t, err) - - drID = f.executeDataRequestFlow( - t, testwasms.SampleTallyWasm(), testwasms.SampleTallyWasm2(), - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte("memo")), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - }) - - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - dataResultAfter, err := f.batchingKeeper.GetLatestDataResult(f.Context(), drID) - require.NoError(t, err) - require.Equal(t, uint32(0), dataResultAfter.ExitCode) - require.Contains(t, string(dataResultAfter.Result), "VM_MODE=tally") - - dataResultsAfter, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Contains(t, dataResultsAfter, *dataResultAfter) -} - -func TestEndBlock_ChunkedContractQuery(t *testing.T) { - f := initFixture(t) - - // Create more data requests than the max number of data requests per query. - numDataRequests := tallykeeper.MaxDataRequestsPerQuery + 5 - - for range numDataRequests { - f.executeDataRequestFlow( - t, nil, nil, - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("memo-%d", rand.Uint64()))), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - }) - } - - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Len(t, dataResults, int(numDataRequests)) -} - -func TestEndBlock_ChunkedContractQuery_MaxTalliesPerBlock(t *testing.T) { - f := initFixture(t) - - // Create more data requests than the max number of data requests per query. - numDataRequests := tallykeeper.MaxDataRequestsPerQuery + 10 - - params := types.DefaultParams() - params.MaxTalliesPerBlock = numDataRequests - f.tallyKeeper.SetParams(f.Context(), params) - - for range numDataRequests { - f.executeDataRequestFlow( - t, nil, nil, - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("memo-%d", rand.Uint64()))), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - }) - } - - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Len(t, dataResults, int(numDataRequests)) -} - -func TestEndBlock_ChunkedContractQuery_LowMaxTalliesPerBlock(t *testing.T) { - f := initFixture(t) - - // Create less data requests than the max number of data requests per query. - numDataRequests := tallykeeper.MaxDataRequestsPerQuery - 25 - - params := types.DefaultParams() - params.MaxTalliesPerBlock = 1 - f.tallyKeeper.SetParams(f.Context(), params) - - for range numDataRequests { - f.executeDataRequestFlow( - t, nil, nil, - 1, 1, 1, false, - commitRevealConfig{ - requestHeight: 1, - requestMemo: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("memo-%d", rand.Uint64()))), - reveal: base64.StdEncoding.EncodeToString([]byte("reveal")), - }) - } - - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Len(t, dataResults, 1) -} - -func TestEndBlock_PausedContract(t *testing.T) { - f := initFixture(t) - stakers := f.addStakers(t, 5) - zeroHash := make([]byte, 32) - - // When the contract is paused the DR poster should get a full refund and end up with the same balance as before posting - beforeBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) - - noCommitsDr, err := f.postDataRequest(zeroHash, zeroHash, base64.StdEncoding.EncodeToString([]byte("noCommits")), 1) - require.NoError(t, err) - - noRevealsDr, err := f.postDataRequest(zeroHash, zeroHash, base64.StdEncoding.EncodeToString([]byte("noReveals")), 1) - require.NoError(t, err) - - _, err = f.commitDataRequest( - stakers[:1], noRevealsDr.Height, noRevealsDr.DrID, - commitRevealConfig{ - requestHeight: 1, - reveal: base64.StdEncoding.EncodeToString([]byte("sike")), - }) - require.NoError(t, err) - - resolvedDr, err := f.postDataRequest(zeroHash, zeroHash, base64.StdEncoding.EncodeToString([]byte("resolved")), 1) - require.NoError(t, err) - - revealMsgs, err := f.commitDataRequest( - stakers[:1], resolvedDr.Height, resolvedDr.DrID, - commitRevealConfig{ - requestHeight: 1, - reveal: base64.StdEncoding.EncodeToString([]byte("sike")), - }) - require.NoError(t, err) - - err = f.executeReveals(stakers, revealMsgs) - require.NoError(t, err) - - afterPostBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) - require.True(t, afterPostBalance.IsLT(beforeBalance), "Poster should have escrowed funds") - - f.pauseContract(t) - - var noRevealsResult *batchingtypes.DataResult - - // Ensure the DR without commitments and the DR without reveals are timed out - for i := range defaultCommitTimeoutBlocks { - f.AddBlock() - - // DRs in the reveal stage time out before DRs in the commit stage - if i == defaultRevealTimeoutBlocks-1 { - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - require.NotContains(t, f.logBuf.String(), "ERR") - - noRevealsResult, err = f.batchingKeeper.GetLatestDataResult(f.Context(), noRevealsDr.DrID) - require.NoError(t, err) - require.Equal(t, uint32(types.TallyExitCodeContractPaused), noRevealsResult.ExitCode) - - resolvedResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), resolvedDr.DrID) - require.NoError(t, err) - require.Equal(t, uint32(types.TallyExitCodeContractPaused), resolvedResult.ExitCode) - } - } - - err = f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - require.NotContains(t, f.logBuf.String(), "ERR") - - noCommitsResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), noCommitsDr.DrID) - require.NoError(t, err) - require.NotEqual(t, "", noCommitsResult.Id, "Result ID should not be empty") - require.Equal(t, uint32(types.TallyExitCodeContractPaused), noCommitsResult.ExitCode) - - // Ensure the DR without reveals was removed from the contract and not processed again - noRevealsResultAfterTimeout, err := f.batchingKeeper.GetLatestDataResult(f.Context(), noRevealsDr.DrID) - require.NoError(t, err) - require.Equal(t, int(noRevealsResultAfterTimeout.BlockHeight), int(noRevealsResult.BlockHeight), "Already resolved DR was processed again") - - // Ensure the poster got a full refund for all the posted DRs. - afterProcessingBalance := f.bankKeeper.GetBalance(f.Context(), f.deployer, bondDenom) - diff := afterProcessingBalance.Sub(beforeBalance) - require.Equal(t, "0aseda", diff.String()) -} - -// TestTallyTestItems executes the 100 randomly selected tally programs and -// verifies their results in the batching module store. -func TestTallyTestItems(t *testing.T) { - f := initFixture(t) - - numRequests := 100 - drIDs := make([]string, numRequests) - testItems := make([]testwasms.TallyTestItem, numRequests) - for i := range numRequests { - drIDs[i], testItems[i] = f.executeDataRequestFlowWithTallyTestItem(t, []byte(fmt.Sprintf("%d", i))) - } - - err := f.tallyKeeper.EndBlock(f.Context()) - require.NoError(t, err) - - // Check the batching module store for the data results. - dataResults, err := f.batchingKeeper.GetDataResults(f.Context(), false) - require.NoError(t, err) - require.Equal(t, numRequests, len(dataResults)) - - for i, drID := range drIDs { - dataResult, err := f.batchingKeeper.GetLatestDataResult(f.Context(), drID) - require.NoError(t, err) - - require.Equal(t, 64, len(dataResult.Id)) - require.Equal(t, uint64(f.Context().BlockHeight()), dataResult.DrBlockHeight) - require.Equal(t, uint64(f.Context().BlockHeight()), dataResult.BlockHeight) - require.Equal(t, uint64(f.Context().BlockHeader().Time.Unix()), dataResult.BlockTimestamp) - - require.Equal(t, testItems[i].ExpectedResult, dataResult.Result) - require.Equal(t, testItems[i].ExpectedExitCode, dataResult.ExitCode) - require.Equal(t, testItems[i].ExpectedGasUsed.String(), dataResult.GasUsed.String()) - - require.Contains(t, dataResults, *dataResult) - } -} diff --git a/x/tally/keeper/genesis_test.go b/x/tally/keeper/genesis_test.go deleted file mode 100644 index 1ea10c59..00000000 --- a/x/tally/keeper/genesis_test.go +++ /dev/null @@ -1,34 +0,0 @@ -package keeper_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/sedaprotocol/seda-chain/x/tally/types" -) - -func TestExportGenesis(t *testing.T) { - f := initFixture(t) - - gs := types.DefaultGenesisState() - gs.Params.FilterGasCostNone = 200_000 - gs.Params.FilterGasCostMultiplierMode = 400_000 - gs.Params.FilterGasCostMultiplierMAD = 600_000 - f.tallyKeeper.SetParams(f.Context(), gs.Params) - - err := types.ValidateGenesis(*gs) - require.NoError(t, err) - - // Export and import genesis. - exportGenesis := f.tallyKeeper.ExportGenesis(f.Context()) - - err = types.ValidateGenesis(exportGenesis) - require.NoError(t, err) - - f.tallyKeeper.InitGenesis(f.Context(), exportGenesis) - - afterParams, err := f.tallyKeeper.GetParams(f.Context()) - require.NoError(t, err) - require.Equal(t, gs.Params, afterParams) -} diff --git a/x/tally/keeper/keeper.go b/x/tally/keeper/keeper.go deleted file mode 100644 index e654ab54..00000000 --- a/x/tally/keeper/keeper.go +++ /dev/null @@ -1,68 +0,0 @@ -package keeper - -import ( - "fmt" - - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - - "cosmossdk.io/collections" - storetypes "cosmossdk.io/core/store" - "cosmossdk.io/log" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/tally/types" -) - -type Keeper struct { - wasmStorageKeeper types.WasmStorageKeeper - batchingKeeper types.BatchingKeeper - dataProxyKeeper types.DataProxyKeeper - wasmKeeper wasmtypes.ContractOpsKeeper - wasmViewKeeper wasmtypes.ViewKeeper - authority string - - Schema collections.Schema - params collections.Item[types.Params] -} - -func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, wsk types.WasmStorageKeeper, bk types.BatchingKeeper, dpk types.DataProxyKeeper, wk wasmtypes.ContractOpsKeeper, wvk wasmtypes.ViewKeeper, authority string) Keeper { - sb := collections.NewSchemaBuilder(storeService) - - k := Keeper{ - wasmStorageKeeper: wsk, - batchingKeeper: bk, - dataProxyKeeper: dpk, - wasmKeeper: wk, - wasmViewKeeper: wvk, - params: collections.NewItem(sb, types.ParamsPrefix, "params", codec.CollValue[types.Params](cdc)), - authority: authority, - } - return k -} - -// GetAuthority returns the module's authority. -func (k Keeper) GetAuthority() string { - return k.authority -} - -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { - return k.params.Set(ctx, params) -} - -func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { - return k.params.Get(ctx) -} - -func (k Keeper) GetMaxTallyGasLimit(ctx sdk.Context) (uint64, error) { - params, err := k.params.Get(ctx) - if err != nil { - return 0, err - } - return params.MaxTallyGasLimit, nil -} - -func (k Keeper) Logger(ctx sdk.Context) log.Logger { - return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) -} diff --git a/x/tally/keeper/msg_server.go b/x/tally/keeper/msg_server.go deleted file mode 100644 index 9c5a4917..00000000 --- a/x/tally/keeper/msg_server.go +++ /dev/null @@ -1,42 +0,0 @@ -package keeper - -import ( - "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - "github.com/sedaprotocol/seda-chain/x/tally/types" -) - -type msgServer struct { - Keeper -} - -var _ types.MsgServer = msgServer{} - -// NewMsgServerImpl returns an implementation of the MsgServer interface -// for the provided Keeper. -func NewMsgServerImpl(keeper Keeper) types.MsgServer { - return &msgServer{Keeper: keeper} -} - -func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { - ctx := sdk.UnwrapSDKContext(goCtx) - - if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid authority address: %s", msg.Authority) - } - if m.GetAuthority() != msg.Authority { - return nil, sdkerrors.ErrorInvalidSigner.Wrapf("unauthorized authority; expected %s, got %s", m.GetAuthority(), msg.Authority) - } - - if err := msg.Params.Validate(); err != nil { - return nil, err - } - if err := m.SetParams(ctx, msg.Params); err != nil { - return nil, err - } - - return &types.MsgUpdateParamsResponse{}, nil -} diff --git a/x/tally/keeper/testdata/fuzz/FuzzEndBlock/0 b/x/tally/keeper/testdata/fuzz/FuzzEndBlock/0 deleted file mode 100644 index 478a2f55..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzEndBlock/0 +++ /dev/null @@ -1,6 +0,0 @@ -go test fuzz v1 -[]byte("\x7b\x22\x72\x65\x73\x75\x6c\x74\x22\x3a\x20\x7b\x22\x74\x65\x78\x74\x22\x3a\x20\x22\x41\x22\x7d\x7d") -[]byte("\x16\x1b\x0d\x3a\x1e\xfb\xf2\xf7\xd2\xf1\x30\xf6\x8a\x2c\xcf\x8f\x8f\x32\x20\xe8") -byte('\x00') -uint64(12500) -uint64(5375000000000) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1b0d714eddf709c2 b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1b0d714eddf709c2 deleted file mode 100644 index 7507f884..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1b0d714eddf709c2 +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(4789345123000) -uint64(4234567890000) -uint64(4987654321000) -uint64(5176543210000) -uint64(4887654320000) -uint64(5054321098000) -uint64(4911111110000) -uint64(5133333330000) -uint64(4999999999000) -uint64(4822222220000) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1e1e3d08130fcadb b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1e1e3d08130fcadb deleted file mode 100644 index d68b3c8f..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/1e1e3d08130fcadb +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(4789345123000) -uint64(4234567890000) -uint64(4987654321000) -uint64(5176543210000) -uint64(4887654320000) -uint64(0) -uint64(4911111110000) -uint64(5133333330000) -uint64(4999999999000) -uint64(4822222220000) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/99dadfaf204274c0 b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/99dadfaf204274c0 deleted file mode 100644 index a85c09bd..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/99dadfaf204274c0 +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(184467440737095520) -uint64(184467440737095516) -uint64(184467440737095523) -uint64(184467440737095516) -uint64(184467440737095516) -uint64(184467440737095516) -uint64(184467440737095521) -uint64(184467440737095516) -uint64(184467440737095516) -uint64(184467440737095516) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/f398f3c04660aac4 b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/f398f3c04660aac4 deleted file mode 100644 index 381c6fd0..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/f398f3c04660aac4 +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(518) -uint64(28) -uint64(488) -uint64(31) -uint64(31) -uint64(123) -uint64(35) -uint64(16) -uint64(139) -uint64(78) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/fb3d0ffd6b0296afgo b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/fb3d0ffd6b0296afgo deleted file mode 100644 index 4ed7daad..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/fb3d0ffd6b0296afgo +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) -uint64(4999999999999) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/max b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/max deleted file mode 100644 index 1c71c90f..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/max +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) -uint64(999999999999999999) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix deleted file mode 100644 index 911d46b7..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(502) -uint64(999999999999999999) -uint64(291101) -uint64(5176543210000) -uint64(488765) -uint64(14) -uint64(4914) -uint64(5133333330000) -uint64(4999999999000) -uint64(920004) diff --git a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix2 b/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix2 deleted file mode 100644 index 1549d3c7..00000000 --- a/x/tally/keeper/testdata/fuzz/FuzzGasMetering/mix2 +++ /dev/null @@ -1,11 +0,0 @@ -go test fuzz v1 -uint64(848882003) -uint64(4234567890000) -uint64(4987654321000) -uint64(410049283) -uint64(4887654320000) -uint64(200) -uint64(4911111110000) -uint64(5133333330000) -uint64(12) -uint64(949920) diff --git a/x/tally/types/abci_types.go b/x/tally/types/abci_types.go deleted file mode 100644 index 1d55b74f..00000000 --- a/x/tally/types/abci_types.go +++ /dev/null @@ -1,267 +0,0 @@ -package types - -import ( - "encoding/base64" - "encoding/hex" - "encoding/json" - "fmt" - "sort" - - "cosmossdk.io/math" - - "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-wasm-vm/tallyvm/v3" - - batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" -) - -type ContractListResponse struct { - IsPaused bool `json:"is_paused"` - DataRequests []Request `json:"data_requests"` - LastSeenIndex LastSeenIndex `json:"last_seen_index"` -} - -// LastSeenIndex is a struct that contains the key of the last seen index in the data request -// list in the contract. The exact type of the key is not important so we simply store is as a -// string which can be used directly in the query. -type LastSeenIndex struct { - index string -} - -func (l *LastSeenIndex) UnmarshalJSON(data []byte) (err error) { - if data == nil || string(data) == "null" { - *l = LastSeenIndex{index: "null"} - } else { - *l = LastSeenIndex{index: string(data)} - } - - return nil -} - -func EmptyLastSeenIndex() LastSeenIndex { - return LastSeenIndex{index: "null"} -} - -func (l *LastSeenIndex) String() string { - return l.index -} - -type Request struct { - ID string `json:"id"` - Height uint64 `json:"height"` - ExecProgramID string `json:"exec_program_id"` - ExecInputs string `json:"exec_inputs"` - ExecGasLimit uint64 `json:"exec_gas_limit"` - TallyProgramID string `json:"tally_program_id"` - TallyInputs string `json:"tally_inputs"` - TallyGasLimit uint64 `json:"tally_gas_limit"` - PostedGasPrice string `json:"posted_gas_price"` - Memo string `json:"memo"` - PaybackAddress string `json:"payback_address"` - ReplicationFactor uint16 `json:"replication_factor"` - ConsensusFilter string `json:"consensus_filter"` - Commits map[string][]byte `json:"commits"` - Reveals map[string]RevealBody `json:"reveals"` - SedaPayload string `json:"seda_payload"` - Version string `json:"version"` -} - -// Validate validates the request fields and returns any validation error along -// with a partially filled DataResult containing the valid fields that were -// successfully decoded. -func (req *Request) ToResult(ctx types.Context) (result batchingtypes.DataResult, encodingErr error) { - // If for whatever reason the request ID is not a valid hex string there is - // no way to proceed, so we're simply going panic. - // This should never happen since encoding bytes to hex is an operation that - // can't fail on the contract (Rust) side. - if _, err := hex.DecodeString(req.ID); err != nil { - panic(fmt.Sprintf("invalid request ID: %s", req.ID)) - } - - result.DrId = req.ID - result.DrBlockHeight = req.Height - result.Version = req.Version - //nolint:gosec // G115: We shouldn't get negative block heights. - result.BlockHeight = uint64(ctx.BlockHeight()) - //nolint:gosec // G115: We shouldn't get negative timestamps. - result.BlockTimestamp = uint64(ctx.BlockTime().Unix()) - - // Validate PaybackAddress - if _, err := base64.StdEncoding.DecodeString(req.PaybackAddress); err != nil { - encodingErr = fmt.Errorf("invalid payback address: %w", err) - result.PaybackAddress = base64.RawStdEncoding.EncodeToString([]byte("")) - } else { - result.PaybackAddress = req.PaybackAddress - } - - // Validate SedaPayload - if _, err := base64.StdEncoding.DecodeString(req.SedaPayload); err != nil { - encodingErr = fmt.Errorf("invalid seda payload: %w", err) - result.SedaPayload = base64.RawStdEncoding.EncodeToString([]byte("")) - } else { - result.SedaPayload = req.SedaPayload - } - - return result, encodingErr -} - -// SanitizeReveals returns sanitized reveals, executors, and gas reports. The -// three slices are sorted by executor with given entropies and have the same -// ordering. Each reveal's reported proxy public keys are also sorted. -func (req *Request) SanitizeReveals(height int64) ([]Reveal, []string, []uint64) { - reveals := make([]Reveal, len(req.Reveals)) - i := 0 - for executor, reveal := range req.Reveals { - reveals[i] = Reveal{Executor: executor, RevealBody: reveal} - sort.Strings(reveals[i].ProxyPubKeys) - i++ - } - - sortedReveals := HashSort(reveals, GetEntropy(req.ID, height)) - - executors := make([]string, len(sortedReveals)) - gasReports := make([]uint64, len(sortedReveals)) - for i, reveal := range sortedReveals { - executors[i] = reveal.Executor - gasReports[i] = reveal.GasUsed - } - return sortedReveals, executors, gasReports -} - -var _ HashSortable = Reveal{} - -type Reveal struct { - Executor string // executor ID (hex-encoded public key) - RevealBody -} - -func (r Reveal) GetSortKey() []byte { - return []byte(r.Executor) -} - -type RevealBody struct { - RequestID string `json:"dr_id"` - RequestBlockHeight uint64 `json:"dr_block_height"` - ExitCode byte `json:"exit_code"` - GasUsed uint64 `json:"gas_used"` - Reveal string `json:"reveal"` // base64-encoded string - ProxyPubKeys []string `json:"proxy_public_keys"` -} - -func (u *RevealBody) MarshalJSON() ([]byte, error) { - revealBytes, err := base64.StdEncoding.DecodeString(u.Reveal) - if err != nil { - return nil, err - } - - type Alias RevealBody - return json.Marshal(&struct { - Reveal []int `json:"reveal"` - *Alias - }{ - Reveal: bytesToIntSlice(revealBytes), - Alias: (*Alias)(u), - }) -} - -func bytesToIntSlice(bytes []byte) []int { - intSlice := make([]int, len(bytes)) - for i, b := range bytes { - intSlice[i] = int(b) - } - return intSlice -} - -type VMResult struct { - Stdout []string - Stderr []string - Result []byte - GasUsed uint64 - ExitCode uint32 - ExitMessage string -} - -// MapVMResult maps a tallyvm.VmResult to a VmResult, taking care of checking the result pointer -// and setting the exit message if the result is empty. This allows us to display the exit message -// to the end user. -func MapVMResult(vmRes tallyvm.VmResult) VMResult { - result := VMResult{ - //nolint:gosec // G115: We shouldn't get negative exit code anyway. - ExitCode: uint32(vmRes.ExitInfo.ExitCode), - ExitMessage: vmRes.ExitInfo.ExitMessage, - Stdout: vmRes.Stdout, - Stderr: vmRes.Stderr, - GasUsed: vmRes.GasUsed, - } - - if vmRes.Result == nil || (vmRes.ResultLen == 0 && vmRes.ExitInfo.ExitCode != 0) { - result.Result = []byte(vmRes.ExitInfo.ExitMessage) - } else if vmRes.Result != nil { - result.Result = *vmRes.Result - } - - return result -} - -type Distribution struct { - Burn *DistributionBurn `json:"burn,omitempty"` - ExecutorReward *DistributionExecutorReward `json:"executor_reward,omitempty"` - DataProxyReward *DistributionDataProxyReward `json:"data_proxy_reward,omitempty"` -} - -type DistributionBurn struct { - Amount math.Int `json:"amount"` -} - -type DistributionDataProxyReward struct { - PayoutAddress string `json:"payout_address"` - Amount math.Int `json:"amount"` - // The public key of the data proxy as a hex string - PublicKey string `json:"public_key"` -} - -type DistributionExecutorReward struct { - Amount math.Int `json:"amount"` - // The public key of the executor as a hex string - Identity string `json:"identity"` -} - -func NewBurn(amount, gasPrice math.Int) Distribution { - return Distribution{ - Burn: &DistributionBurn{Amount: amount.Mul(gasPrice)}, - } -} - -func NewDataProxyReward(pubkey, payoutAddr string, amount, gasPrice math.Int) Distribution { - return Distribution{ - DataProxyReward: &DistributionDataProxyReward{ - PayoutAddress: payoutAddr, - Amount: amount.Mul(gasPrice), - PublicKey: pubkey, - }, - } -} - -func NewExecutorReward(identity string, amount, gasPrice math.Int) Distribution { - return Distribution{ - ExecutorReward: &DistributionExecutorReward{ - Identity: identity, - Amount: amount.Mul(gasPrice), - }, - } -} - -func MarshalSudoRemoveDataRequests(processedReqs map[string][]Distribution) ([]byte, error) { - return json.Marshal(struct { - SudoRemoveDataRequests struct { - Requests map[string][]Distribution `json:"requests"` - } `json:"remove_data_requests"` - }{ - SudoRemoveDataRequests: struct { - Requests map[string][]Distribution `json:"requests"` - }{ - Requests: processedReqs, - }, - }) -} diff --git a/x/tally/types/errors.go b/x/tally/types/errors.go deleted file mode 100644 index 3d19ddc8..00000000 --- a/x/tally/types/errors.go +++ /dev/null @@ -1,26 +0,0 @@ -package types - -import ( - "cosmossdk.io/errors" -) - -var ( - // Errors used in filter: - ErrInvalidFilterType = errors.Register("tally", 2, "invalid filter type") - ErrFilterInputTooShort = errors.Register("tally", 3, "filter input length too short") - ErrInvalidPathLen = errors.Register("tally", 4, "invalid JSON path length") - ErrInvalidNumberType = errors.Register("tally", 5, "invalid number type specified") - ErrInvalidFilterInput = errors.Register("tally", 6, "invalid filter input") - ErrInvalidSigmaMultiplier = errors.Register("tally", 7, "invalid sigma multiplier") - ErrOutOfTallyGas = errors.Register("tally", 8, "out of tally gas") - ErrConsensusInError = errors.Register("tally", 9, "consensus in error") - ErrNoConsensus = errors.Register("tally", 10, "> 1/3 of reveals do not agree on reveal data") - ErrNoBasicConsensus = errors.Register("tally", 11, "> 1/3 of reveals do not agree on (exit_code_success, proxy_pub_keys)") - ErrFilterDidNotRun = errors.Register("tally", 12, "filter did not run due to not enough commits") - // Errors used in tally program execution: - ErrDecodingPaybackAddress = errors.Register("tally", 13, "failed to decode payback address") - ErrFindingTallyProgram = errors.Register("tally", 14, "failed to find tally program") - ErrDecodingTallyInputs = errors.Register("tally", 15, "failed to decode tally inputs") - ErrConstructingTallyVMArgs = errors.Register("tally", 16, "failed to construct tally VM arguments") - ErrGettingMaxTallyGasLimit = errors.Register("tally", 17, "failed to get max tally gas limit") -) diff --git a/x/tally/types/expected_keepers.go b/x/tally/types/expected_keepers.go deleted file mode 100644 index e7838af9..00000000 --- a/x/tally/types/expected_keepers.go +++ /dev/null @@ -1,16 +0,0 @@ -package types - -import ( - "context" - - batchingtypes "github.com/sedaprotocol/seda-chain/x/batching/types" - dataproxytypes "github.com/sedaprotocol/seda-chain/x/data-proxy/types" -) - -type BatchingKeeper interface { - SetDataResultForBatching(ctx context.Context, result batchingtypes.DataResult) error -} - -type DataProxyKeeper interface { - GetDataProxyConfig(ctx context.Context, pubKey []byte) (result dataproxytypes.ProxyConfig, err error) -} diff --git a/x/tally/types/keys.go b/x/tally/types/keys.go deleted file mode 100644 index d0903979..00000000 --- a/x/tally/types/keys.go +++ /dev/null @@ -1,10 +0,0 @@ -package types - -import "cosmossdk.io/collections" - -const ( - ModuleName = "tally" - StoreKey = ModuleName -) - -var ParamsPrefix = collections.NewPrefix(0) diff --git a/x/tally/types/params.go b/x/tally/types/params.go deleted file mode 100644 index 15adec1b..00000000 --- a/x/tally/types/params.go +++ /dev/null @@ -1,80 +0,0 @@ -package types - -import ( - fmt "fmt" - - "cosmossdk.io/math" - - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -const ( - DefaultMaxResultSize = 1024 - DefaultMaxTallyGasLimit = 50_000_000_000_000 - DefaultFilterGasCostNone = 100_000 - DefaultFilterGasCostMultiplierMode = 100_000 - DefaultFilterGasCostMultiplierMAD = 100_000 - DefaultGasCostBase = 1_000_000_000_000 - DefaultExecutionGasCostFallback = 5_000_000_000_000 - DefaultMaxTalliesPerBlock = 100 -) - -var DefaultBurnRatio = math.LegacyNewDecWithPrec(2, 1) - -// DefaultParams returns default tally module parameters. -func DefaultParams() Params { - return Params{ - MaxResultSize: DefaultMaxResultSize, - MaxTallyGasLimit: DefaultMaxTallyGasLimit, - FilterGasCostNone: DefaultFilterGasCostNone, - FilterGasCostMultiplierMode: DefaultFilterGasCostMultiplierMode, - FilterGasCostMultiplierMAD: DefaultFilterGasCostMultiplierMAD, - GasCostBase: DefaultGasCostBase, - ExecutionGasCostFallback: DefaultExecutionGasCostFallback, - BurnRatio: DefaultBurnRatio, - MaxTalliesPerBlock: DefaultMaxTalliesPerBlock, - } -} - -// ValidateBasic performs basic validation on tally module parameters. -func (p *Params) Validate() error { - if p.MaxResultSize <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("max result size must be greater than 0: %d", p.MaxResultSize) - } - if p.MaxTallyGasLimit <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("max tally gas limit must be greater than 0: %d", p.MaxTallyGasLimit) - } - if p.FilterGasCostNone <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (none) must be greater than 0: %d", p.FilterGasCostNone) - } - if p.FilterGasCostMultiplierMode <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (mode) must be greater than 0: %d", p.FilterGasCostMultiplierMode) - } - if p.FilterGasCostMultiplierMAD <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("filter gas cost (MAD) must be greater than 0: %d", p.FilterGasCostMultiplierMAD) - } - if p.GasCostBase <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("base gas cost must be greater than 0: %d", p.GasCostBase) - } - if p.ExecutionGasCostFallback <= 0 { - return sdkerrors.ErrInvalidRequest.Wrapf("execution gas cost fallback must be greater than 0: %d", p.ExecutionGasCostFallback) - } - return validateBurnRatio(p.BurnRatio) -} - -func validateBurnRatio(i interface{}) error { - v, ok := i.(math.LegacyDec) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - if v.IsNil() { - return fmt.Errorf("burn ratio must be not nil") - } - if v.IsNegative() { - return fmt.Errorf("burn ratio must be positive: %s", v) - } - if v.GT(math.LegacyOneDec()) { - return fmt.Errorf("burn ratio too large: %s", v) - } - return nil -} diff --git a/x/tally/types/tally.pb.go b/x/tally/types/tally.pb.go deleted file mode 100644 index 2b8aaae4..00000000 --- a/x/tally/types/tally.pb.go +++ /dev/null @@ -1,629 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/tally/v1/tally.proto - -package types - -import ( - cosmossdk_io_math "cosmossdk.io/math" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/cosmos-sdk/types/tx/amino" - _ "github.com/cosmos/gogoproto/gogoproto" - proto "github.com/cosmos/gogoproto/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// Params defines the parameters for the tally module. -type Params struct { - // MaxTallyGasLimit is the maximum gas limit for a tally request. - MaxTallyGasLimit uint64 `protobuf:"varint,1,opt,name=max_tally_gas_limit,json=maxTallyGasLimit,proto3" json:"max_tally_gas_limit,omitempty"` - // FilterGasCostNone is the gas cost for a filter type none. - FilterGasCostNone uint64 `protobuf:"varint,2,opt,name=filter_gas_cost_none,json=filterGasCostNone,proto3" json:"filter_gas_cost_none,omitempty"` - // FilterGasCostMultiplierMode is the gas cost multiplier for a filter type - // mode. - FilterGasCostMultiplierMode uint64 `protobuf:"varint,3,opt,name=filter_gas_cost_multiplier_mode,json=filterGasCostMultiplierMode,proto3" json:"filter_gas_cost_multiplier_mode,omitempty"` - // FilterGasCostMAD is the gas cost multiplier for a filter type - // Median Absolute Deviation. - FilterGasCostMultiplierMAD uint64 `protobuf:"varint,4,opt,name=filter_gas_cost_multiplier_m_a_d,json=filterGasCostMultiplierMAD,proto3" json:"filter_gas_cost_multiplier_m_a_d,omitempty"` - // GasCostBase is the base gas cost for a data request. - GasCostBase uint64 `protobuf:"varint,5,opt,name=gas_cost_base,json=gasCostBase,proto3" json:"gas_cost_base,omitempty"` - // GasCostFallback is the gas cost incurred for data request execution when - // even basic consensus has not been reached. - ExecutionGasCostFallback uint64 `protobuf:"varint,6,opt,name=execution_gas_cost_fallback,json=executionGasCostFallback,proto3" json:"execution_gas_cost_fallback,omitempty"` - // BurnRatio is the ratio of the gas cost to be burned in case of reduced - // payout scenarios. - BurnRatio cosmossdk_io_math.LegacyDec `protobuf:"bytes,7,opt,name=burn_ratio,json=burnRatio,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"burn_ratio"` - // MaxResultSize is the maximum size of the result of a data request in bytes. - MaxResultSize uint32 `protobuf:"varint,8,opt,name=max_result_size,json=maxResultSize,proto3" json:"max_result_size,omitempty"` - // MaxTalliesPerBlock specifies the maximum number of tallies per block. - MaxTalliesPerBlock uint32 `protobuf:"varint,9,opt,name=max_tallies_per_block,json=maxTalliesPerBlock,proto3" json:"max_tallies_per_block,omitempty"` -} - -func (m *Params) Reset() { *m = Params{} } -func (m *Params) String() string { return proto.CompactTextString(m) } -func (*Params) ProtoMessage() {} -func (*Params) Descriptor() ([]byte, []int) { - return fileDescriptor_2917df8a6808d5e2, []int{0} -} -func (m *Params) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Params.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Params) XXX_Merge(src proto.Message) { - xxx_messageInfo_Params.Merge(m, src) -} -func (m *Params) XXX_Size() int { - return m.Size() -} -func (m *Params) XXX_DiscardUnknown() { - xxx_messageInfo_Params.DiscardUnknown(m) -} - -var xxx_messageInfo_Params proto.InternalMessageInfo - -func (m *Params) GetMaxTallyGasLimit() uint64 { - if m != nil { - return m.MaxTallyGasLimit - } - return 0 -} - -func (m *Params) GetFilterGasCostNone() uint64 { - if m != nil { - return m.FilterGasCostNone - } - return 0 -} - -func (m *Params) GetFilterGasCostMultiplierMode() uint64 { - if m != nil { - return m.FilterGasCostMultiplierMode - } - return 0 -} - -func (m *Params) GetFilterGasCostMultiplierMAD() uint64 { - if m != nil { - return m.FilterGasCostMultiplierMAD - } - return 0 -} - -func (m *Params) GetGasCostBase() uint64 { - if m != nil { - return m.GasCostBase - } - return 0 -} - -func (m *Params) GetExecutionGasCostFallback() uint64 { - if m != nil { - return m.ExecutionGasCostFallback - } - return 0 -} - -func (m *Params) GetMaxResultSize() uint32 { - if m != nil { - return m.MaxResultSize - } - return 0 -} - -func (m *Params) GetMaxTalliesPerBlock() uint32 { - if m != nil { - return m.MaxTalliesPerBlock - } - return 0 -} - -func init() { - proto.RegisterType((*Params)(nil), "sedachain.tally.v1.Params") -} - -func init() { proto.RegisterFile("sedachain/tally/v1/tally.proto", fileDescriptor_2917df8a6808d5e2) } - -var fileDescriptor_2917df8a6808d5e2 = []byte{ - // 482 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0x41, 0x8b, 0x13, 0x3f, - 0x18, 0xc6, 0x3b, 0xff, 0x7f, 0xad, 0x36, 0x52, 0x74, 0xe3, 0x0a, 0x63, 0x0b, 0xd3, 0xb2, 0x07, - 0x29, 0x42, 0x3b, 0x16, 0xc1, 0x9b, 0x07, 0x6b, 0x71, 0x41, 0x76, 0x65, 0xa9, 0x7a, 0xf1, 0x12, - 0xde, 0x49, 0xdf, 0x9d, 0x86, 0x26, 0x93, 0x32, 0x49, 0x97, 0xe9, 0x7e, 0x03, 0x6f, 0x7e, 0x0c, - 0x8f, 0x1e, 0xfc, 0x10, 0x7b, 0x5c, 0x3c, 0x89, 0x87, 0x45, 0xda, 0x83, 0x5f, 0x43, 0x26, 0x19, - 0x2b, 0x0a, 0x7a, 0x09, 0xc9, 0xf3, 0xfe, 0x9e, 0x27, 0x87, 0xe7, 0x25, 0x91, 0xc1, 0x19, 0xf0, - 0x39, 0x88, 0x2c, 0xb6, 0x20, 0xe5, 0x3a, 0x3e, 0x1b, 0xf9, 0xcb, 0x70, 0x99, 0x6b, 0xab, 0x29, - 0xdd, 0xcd, 0x87, 0x5e, 0x3e, 0x1b, 0xb5, 0xef, 0x71, 0x6d, 0x94, 0x36, 0xcc, 0x11, 0xb1, 0x7f, - 0x78, 0xbc, 0xbd, 0x9f, 0xea, 0x54, 0x7b, 0xbd, 0xbc, 0x55, 0xea, 0x1e, 0x28, 0x91, 0xe9, 0xd8, - 0x9d, 0x5e, 0x3a, 0x78, 0x57, 0x27, 0x8d, 0x13, 0xc8, 0x41, 0x19, 0x3a, 0x20, 0x77, 0x14, 0x14, - 0xcc, 0xc5, 0xb3, 0x14, 0x0c, 0x93, 0x42, 0x09, 0x1b, 0x06, 0xbd, 0xa0, 0x5f, 0x9f, 0xde, 0x56, - 0x50, 0xbc, 0x2e, 0x27, 0x87, 0x60, 0x8e, 0x4a, 0x9d, 0xc6, 0x64, 0xff, 0x54, 0x48, 0x8b, 0xb9, - 0x63, 0xb9, 0x36, 0x96, 0x65, 0x3a, 0xc3, 0xf0, 0x3f, 0xc7, 0xef, 0xf9, 0xd9, 0x21, 0x98, 0x67, - 0xda, 0xd8, 0x97, 0x3a, 0x43, 0x3a, 0x21, 0xdd, 0x3f, 0x0d, 0x6a, 0x25, 0xad, 0x58, 0x4a, 0x81, - 0x39, 0x53, 0x7a, 0x86, 0xe1, 0xff, 0xce, 0xdb, 0xf9, 0xcd, 0x7b, 0xbc, 0x63, 0x8e, 0xf5, 0xac, - 0x4c, 0xe9, 0xfd, 0x2b, 0x85, 0x01, 0x9b, 0x85, 0x75, 0x17, 0xd3, 0xfe, 0x5b, 0xcc, 0xd3, 0x09, - 0x3d, 0x20, 0xad, 0x9d, 0x3d, 0x01, 0x83, 0xe1, 0x35, 0x67, 0xb9, 0x99, 0x7a, 0x78, 0x0c, 0x06, - 0xe9, 0x13, 0xd2, 0xc1, 0x02, 0xf9, 0xca, 0x0a, 0x9d, 0xfd, 0xfa, 0xec, 0x14, 0xa4, 0x4c, 0x80, - 0x2f, 0xc2, 0x86, 0x73, 0x84, 0x3b, 0xa4, 0xfa, 0xe7, 0x79, 0x35, 0xa7, 0x6f, 0x08, 0x49, 0x56, - 0x79, 0xc6, 0x72, 0xb0, 0x42, 0x87, 0xd7, 0x7b, 0x41, 0xbf, 0x39, 0x7e, 0x7c, 0x71, 0xd5, 0xad, - 0x7d, 0xbd, 0xea, 0x76, 0x7c, 0x59, 0x66, 0xb6, 0x18, 0x0a, 0x1d, 0x2b, 0xb0, 0xf3, 0xe1, 0x11, - 0xa6, 0xc0, 0xd7, 0x13, 0xe4, 0x9f, 0x3f, 0x0d, 0x48, 0xd5, 0xe5, 0x04, 0xf9, 0x87, 0xef, 0x1f, - 0x1f, 0x04, 0xd3, 0x66, 0x99, 0x34, 0x2d, 0x83, 0xe8, 0x7d, 0x72, 0xab, 0x6c, 0x29, 0x47, 0xb3, - 0x92, 0x96, 0x19, 0x71, 0x8e, 0xe1, 0x8d, 0x5e, 0xd0, 0x6f, 0x4d, 0x5b, 0x0a, 0x8a, 0xa9, 0x53, - 0x5f, 0x89, 0x73, 0xa4, 0x23, 0x72, 0xf7, 0x67, 0x9b, 0x02, 0x0d, 0x5b, 0x62, 0xce, 0x12, 0xa9, - 0xf9, 0x22, 0x6c, 0x3a, 0x9a, 0x56, 0x7d, 0x0a, 0x34, 0x27, 0x98, 0x8f, 0xcb, 0xc9, 0xf8, 0xc5, - 0xc5, 0x26, 0x0a, 0x2e, 0x37, 0x51, 0xf0, 0x6d, 0x13, 0x05, 0xef, 0xb7, 0x51, 0xed, 0x72, 0x1b, - 0xd5, 0xbe, 0x6c, 0xa3, 0xda, 0xdb, 0x87, 0xa9, 0xb0, 0xf3, 0x55, 0x32, 0xe4, 0x5a, 0xc5, 0xe5, - 0x22, 0xba, 0xdd, 0xe1, 0x5a, 0xba, 0xc7, 0xc0, 0xaf, 0x6d, 0x51, 0x2d, 0xae, 0x5d, 0x2f, 0xd1, - 0x24, 0x0d, 0x87, 0x3c, 0xfa, 0x11, 0x00, 0x00, 0xff, 0xff, 0x05, 0x0c, 0x3a, 0xc7, 0xd8, 0x02, - 0x00, 0x00, -} - -func (m *Params) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.MaxTalliesPerBlock != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.MaxTalliesPerBlock)) - i-- - dAtA[i] = 0x48 - } - if m.MaxResultSize != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.MaxResultSize)) - i-- - dAtA[i] = 0x40 - } - { - size := m.BurnRatio.Size() - i -= size - if _, err := m.BurnRatio.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintTally(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x3a - if m.ExecutionGasCostFallback != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.ExecutionGasCostFallback)) - i-- - dAtA[i] = 0x30 - } - if m.GasCostBase != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.GasCostBase)) - i-- - dAtA[i] = 0x28 - } - if m.FilterGasCostMultiplierMAD != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.FilterGasCostMultiplierMAD)) - i-- - dAtA[i] = 0x20 - } - if m.FilterGasCostMultiplierMode != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.FilterGasCostMultiplierMode)) - i-- - dAtA[i] = 0x18 - } - if m.FilterGasCostNone != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.FilterGasCostNone)) - i-- - dAtA[i] = 0x10 - } - if m.MaxTallyGasLimit != 0 { - i = encodeVarintTally(dAtA, i, uint64(m.MaxTallyGasLimit)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintTally(dAtA []byte, offset int, v uint64) int { - offset -= sovTally(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.MaxTallyGasLimit != 0 { - n += 1 + sovTally(uint64(m.MaxTallyGasLimit)) - } - if m.FilterGasCostNone != 0 { - n += 1 + sovTally(uint64(m.FilterGasCostNone)) - } - if m.FilterGasCostMultiplierMode != 0 { - n += 1 + sovTally(uint64(m.FilterGasCostMultiplierMode)) - } - if m.FilterGasCostMultiplierMAD != 0 { - n += 1 + sovTally(uint64(m.FilterGasCostMultiplierMAD)) - } - if m.GasCostBase != 0 { - n += 1 + sovTally(uint64(m.GasCostBase)) - } - if m.ExecutionGasCostFallback != 0 { - n += 1 + sovTally(uint64(m.ExecutionGasCostFallback)) - } - l = m.BurnRatio.Size() - n += 1 + l + sovTally(uint64(l)) - if m.MaxResultSize != 0 { - n += 1 + sovTally(uint64(m.MaxResultSize)) - } - if m.MaxTalliesPerBlock != 0 { - n += 1 + sovTally(uint64(m.MaxTalliesPerBlock)) - } - return n -} - -func sovTally(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTally(x uint64) (n int) { - return sovTally(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *Params) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxTallyGasLimit", wireType) - } - m.MaxTallyGasLimit = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxTallyGasLimit |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostNone", wireType) - } - m.FilterGasCostNone = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.FilterGasCostNone |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostMultiplierMode", wireType) - } - m.FilterGasCostMultiplierMode = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.FilterGasCostMultiplierMode |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field FilterGasCostMultiplierMAD", wireType) - } - m.FilterGasCostMultiplierMAD = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.FilterGasCostMultiplierMAD |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field GasCostBase", wireType) - } - m.GasCostBase = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.GasCostBase |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ExecutionGasCostFallback", wireType) - } - m.ExecutionGasCostFallback = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ExecutionGasCostFallback |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field BurnRatio", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTally - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTally - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.BurnRatio.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxResultSize", wireType) - } - m.MaxResultSize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxResultSize |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field MaxTalliesPerBlock", wireType) - } - m.MaxTalliesPerBlock = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTally - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.MaxTalliesPerBlock |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipTally(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTally - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTally(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTally - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTally - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTally - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTally - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTally - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTally - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTally = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTally = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTally = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/tally/types/tx.pb.go b/x/tally/types/tx.pb.go deleted file mode 100644 index 1abd6b74..00000000 --- a/x/tally/types/tx.pb.go +++ /dev/null @@ -1,592 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: sedachain/tally/v1/tx.proto - -package types - -import ( - context "context" - fmt "fmt" - _ "github.com/cosmos/cosmos-proto" - _ "github.com/cosmos/cosmos-sdk/types/msgservice" - _ "github.com/cosmos/gogoproto/gogoproto" - grpc1 "github.com/cosmos/gogoproto/grpc" - proto "github.com/cosmos/gogoproto/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - io "io" - math "math" - math_bits "math/bits" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package - -// The request message for the UpdateParams method. -type MsgUpdateParams struct { - // authority is the address that controls the module (defaults to x/gov unless - // overwritten). - Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` - Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` -} - -func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } -func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateParams) ProtoMessage() {} -func (*MsgUpdateParams) Descriptor() ([]byte, []int) { - return fileDescriptor_7436d8962ad2b0ac, []int{0} -} -func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateParams.Merge(m, src) -} -func (m *MsgUpdateParams) XXX_Size() int { - return m.Size() -} -func (m *MsgUpdateParams) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo - -func (m *MsgUpdateParams) GetAuthority() string { - if m != nil { - return m.Authority - } - return "" -} - -func (m *MsgUpdateParams) GetParams() Params { - if m != nil { - return m.Params - } - return Params{} -} - -// The response message for the UpdateParams method. -type MsgUpdateParamsResponse struct { -} - -func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } -func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } -func (*MsgUpdateParamsResponse) ProtoMessage() {} -func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_7436d8962ad2b0ac, []int{1} -} -func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) -} -func (m *MsgUpdateParamsResponse) XXX_Size() int { - return m.Size() -} -func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { - xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo - -func init() { - proto.RegisterType((*MsgUpdateParams)(nil), "sedachain.tally.v1.MsgUpdateParams") - proto.RegisterType((*MsgUpdateParamsResponse)(nil), "sedachain.tally.v1.MsgUpdateParamsResponse") -} - -func init() { proto.RegisterFile("sedachain/tally/v1/tx.proto", fileDescriptor_7436d8962ad2b0ac) } - -var fileDescriptor_7436d8962ad2b0ac = []byte{ - // 327 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2e, 0x4e, 0x4d, 0x49, - 0x4c, 0xce, 0x48, 0xcc, 0xcc, 0xd3, 0x2f, 0x49, 0xcc, 0xc9, 0xa9, 0xd4, 0x2f, 0x33, 0xd4, 0x2f, - 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x82, 0x4b, 0xea, 0x81, 0x25, 0xf5, 0xca, - 0x0c, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, 0xd2, 0xfa, 0x20, 0x16, 0x44, 0xa5, 0x94, 0x64, - 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x71, 0x3c, 0x44, 0x02, 0xc2, 0x81, 0x4a, 0x89, 0x43, 0x78, 0xfa, - 0xb9, 0xc5, 0xe9, 0x20, 0xc3, 0x73, 0x8b, 0xd3, 0xa1, 0x12, 0x72, 0xd8, 0xac, 0x06, 0x5b, 0x03, - 0x96, 0x57, 0x9a, 0xcc, 0xc8, 0xc5, 0xef, 0x5b, 0x9c, 0x1e, 0x5a, 0x90, 0x92, 0x58, 0x92, 0x1a, - 0x90, 0x58, 0x94, 0x98, 0x5b, 0x2c, 0x64, 0xc6, 0xc5, 0x99, 0x58, 0x5a, 0x92, 0x91, 0x5f, 0x94, - 0x59, 0x52, 0x29, 0xc1, 0xa8, 0xc0, 0xa8, 0xc1, 0xe9, 0x24, 0x71, 0x69, 0x8b, 0xae, 0x08, 0xd4, - 0x46, 0xc7, 0x94, 0x94, 0xa2, 0xd4, 0xe2, 0xe2, 0xe0, 0x92, 0xa2, 0xcc, 0xbc, 0xf4, 0x20, 0x84, - 0x52, 0x21, 0x0b, 0x2e, 0xb6, 0x02, 0xb0, 0x09, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xdc, 0x46, 0x52, - 0x7a, 0x98, 0x5e, 0xd3, 0x83, 0xd8, 0xe1, 0xc4, 0x72, 0xe2, 0x9e, 0x3c, 0x43, 0x10, 0x54, 0xbd, - 0x15, 0x5f, 0xd3, 0xf3, 0x0d, 0x5a, 0x08, 0x93, 0x94, 0x24, 0xb9, 0xc4, 0xd1, 0x1c, 0x15, 0x94, - 0x5a, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x6a, 0x94, 0xc7, 0xc5, 0xec, 0x5b, 0x9c, 0x2e, 0x94, 0xc0, - 0xc5, 0x83, 0xe2, 0x66, 0x65, 0x6c, 0x76, 0xa1, 0x99, 0x21, 0xa5, 0x4d, 0x84, 0x22, 0x98, 0x45, - 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, 0x3a, 0x79, 0x9d, 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, 0x41, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, - 0xc8, 0x5c, 0x70, 0x80, 0x26, 0xe7, 0xe7, 0x80, 0x39, 0xba, 0x90, 0x30, 0xaf, 0x80, 0x86, 0x7a, - 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x58, 0x89, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xee, - 0xce, 0x08, 0xed, 0x10, 0x02, 0x00, 0x00, -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// MsgClient is the client API for Msg service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type MsgClient interface { - // The UpdateParams method updates the module's parameters. - UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) -} - -type msgClient struct { - cc grpc1.ClientConn -} - -func NewMsgClient(cc grpc1.ClientConn) MsgClient { - return &msgClient{cc} -} - -func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { - out := new(MsgUpdateParamsResponse) - err := c.cc.Invoke(ctx, "/sedachain.tally.v1.Msg/UpdateParams", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// MsgServer is the server API for Msg service. -type MsgServer interface { - // The UpdateParams method updates the module's parameters. - UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) -} - -// UnimplementedMsgServer can be embedded to have forward compatible implementations. -type UnimplementedMsgServer struct { -} - -func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") -} - -func RegisterMsgServer(s grpc1.Server, srv MsgServer) { - s.RegisterService(&_Msg_serviceDesc, srv) -} - -func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(MsgUpdateParams) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(MsgServer).UpdateParams(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/sedachain.tally.v1.Msg/UpdateParams", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) - } - return interceptor(ctx, in, info, handler) -} - -var Msg_serviceDesc = _Msg_serviceDesc -var _Msg_serviceDesc = grpc.ServiceDesc{ - ServiceName: "sedachain.tally.v1.Msg", - HandlerType: (*MsgServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "UpdateParams", - Handler: _Msg_UpdateParams_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "sedachain/tally/v1/tx.proto", -} - -func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintTx(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - if len(m.Authority) > 0 { - i -= len(m.Authority) - copy(dAtA[i:], m.Authority) - i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func encodeVarintTx(dAtA []byte, offset int, v uint64) int { - offset -= sovTx(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *MsgUpdateParams) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Authority) - if l > 0 { - n += 1 + l + sovTx(uint64(l)) - } - l = m.Params.Size() - n += 1 + l + sovTx(uint64(l)) - return n -} - -func (m *MsgUpdateParamsResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func sovTx(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozTx(x uint64) (n int) { - return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Authority = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthTx - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthTx - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTx - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipTx(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthTx - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipTx(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowTx - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthTx - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupTx - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthTx - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF -} - -var ( - ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") -) diff --git a/x/tally/types/types.go b/x/tally/types/types.go deleted file mode 100644 index 22422e70..00000000 --- a/x/tally/types/types.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -import ( - context "context" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/sedaprotocol/seda-chain/x/wasm-storage/types" -) - -type WasmStorageKeeper interface { - GetCoreContractAddr(ctx context.Context) (sdk.AccAddress, error) - GetOracleProgram(ctx context.Context, hash string) (types.OracleProgram, error) -} diff --git a/x/wasm-storage/keeper/msg_server_test.go b/x/wasm-storage/keeper/msg_server_test.go index 84779614..afea18e9 100644 --- a/x/wasm-storage/keeper/msg_server_test.go +++ b/x/wasm-storage/keeper/msg_server_test.go @@ -469,11 +469,11 @@ func generateTxBytes(t *testing.T, txConfig client.TxConfig, coreContract string if isLastMsgReveal { msg = testutil.RevealMsg("drID", "reveal", "pubKey", "proof", []string{}, 0, 99, 777) } else { - msg = testutil.CommitMsg("drID", "commitment", "pubKey", "proof", 777) + msg = testutil.CommitMsg("drID", "commitment", "pubKey", "proof") } } else { if i%2 == 0 { - msg = testutil.CommitMsg(fmt.Sprintf("drID%d", i), "commitment", fmt.Sprintf("pubKey%d", i), "proof", 777) + msg = testutil.CommitMsg(fmt.Sprintf("drID%d", i), "commitment", fmt.Sprintf("pubKey%d", i), "proof") } else { msg = testutil.RevealMsg(fmt.Sprintf("drID%d", i), "reveal", fmt.Sprintf("pubKey%d", i), "proof", []string{}, 0, 99, 777) } diff --git a/x/wasm/keeper.go b/x/wasm/keeper.go new file mode 100644 index 00000000..1064b2ba --- /dev/null +++ b/x/wasm/keeper.go @@ -0,0 +1,44 @@ +package wasm + +import ( + "context" + + "github.com/CosmWasm/wasmd/x/wasm/keeper" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +//nolint:revive +type WasmStorageKeeper interface { + GetCoreContractAddr(ctx context.Context) (sdk.AccAddress, error) +} + +type StakingKeeper interface { + BondDenom(ctx context.Context) (string, error) +} + +type Keeper struct { + *keeper.Keeper // default wasm keeper + WasmStorageKeeper WasmStorageKeeper // for core contract shim + StakingKeeper StakingKeeper // for core contract shim + cdc codec.Codec // for core contract shim + router keeper.MessageRouter // for core contract shim +} + +func NewKeeper(k *keeper.Keeper, sk StakingKeeper, cdc codec.Codec, router keeper.MessageRouter) *Keeper { + return &Keeper{ + Keeper: k, + StakingKeeper: sk, + cdc: cdc, + router: router, + } +} + +func (k *Keeper) SetWasmStorageKeeper(wsk WasmStorageKeeper) { + k.WasmStorageKeeper = wsk +} + +func (k *Keeper) SetRouter(router keeper.MessageRouter) { + k.router = router +} diff --git a/x/wasm/module.go b/x/wasm/module.go new file mode 100644 index 00000000..32944db0 --- /dev/null +++ b/x/wasm/module.go @@ -0,0 +1,52 @@ +package wasm + +import ( + "github.com/CosmWasm/wasmd/x/wasm" + "github.com/CosmWasm/wasmd/x/wasm/exported" + "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/CosmWasm/wasmd/x/wasm/simulation" + "github.com/CosmWasm/wasmd/x/wasm/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/types/module" +) + +var _ module.AppModule = AppModule{} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule wraps the default AppModule to provide a custom MsgServer that +// redirects Core Contract messages to x/core. +type AppModule struct { + wasm.AppModule + + keeper *Keeper +} + +// NewAppModule creates a new AppModule object +func NewAppModule( + cdc codec.Codec, + keeper *Keeper, + validatorSetSource keeper.ValidatorSetSource, + ak types.AccountKeeper, + bk simulation.BankKeeper, + router *baseapp.MsgServiceRouter, + ss exported.Subspace, +) AppModule { + return AppModule{ + AppModule: wasm.NewAppModule(cdc, keeper.Keeper, validatorSetSource, ak, bk, router, ss), + keeper: keeper, + } +} + +// RegisterServices overrides the default RegisterServices method to register +// the custom MsgServer that redirects Core Contract messages to x/core. +func (am AppModule) RegisterServices(cfg module.Configurator) { + sdkMsgServer := keeper.NewMsgServerImpl(am.keeper.Keeper) + types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(sdkMsgServer, am.keeper)) + + types.RegisterQueryServer(cfg.QueryServer(), keeper.Querier(am.keeper.Keeper)) +} diff --git a/x/wasm/msg_server.go b/x/wasm/msg_server.go new file mode 100644 index 00000000..125b0aa4 --- /dev/null +++ b/x/wasm/msg_server.go @@ -0,0 +1,121 @@ +package wasm + +import ( + "context" + "encoding/json" + + "github.com/CosmWasm/wasmd/x/wasm/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" +) + +type msgServer struct { + types.MsgServer + *Keeper +} + +func NewMsgServerImpl(sdkMsgServer types.MsgServer, keeper *Keeper) types.MsgServer { + ms := &msgServer{ + MsgServer: sdkMsgServer, + Keeper: keeper, + } + return ms +} + +// TODO Override all methods? + +// ExecuteContract overrides the default ExecuteContract method. +func (m msgServer) ExecuteContract(goCtx context.Context, msg *types.MsgExecuteContract) (*types.MsgExecuteContractResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + contractAddr, err := sdk.AccAddressFromBech32(msg.Contract) + if err != nil { + return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid contract address: %s", msg.Contract) + } + coreContractAddr, err := m.WasmStorageKeeper.GetCoreContractAddr(ctx) + if err != nil { + return nil, err + } + if contractAddr.String() != coreContractAddr.String() { + return m.MsgServer.ExecuteContract(goCtx, msg) + } + + err = msg.ValidateBasic() + if err != nil { + return nil, err + } + + bondDenom, err := m.StakingKeeper.BondDenom(ctx) + if err != nil { + return nil, err + } + + // Encode and dispatch. + var coreContractMsg *CoreContractMsg + err = json.Unmarshal(msg.Msg, &coreContractMsg) + if err != nil { + return nil, sdkerrors.ErrInvalidRequest.Wrapf("failed to unmarshal core contract message: %v", err) + } + + var sdkMsg sdk.Msg + switch { + case coreContractMsg.AddToAllowList != nil: + sdkMsg, err = coreContractMsg.AddToAllowList.EncodeToSdkMsg(msg.Sender) + + case coreContractMsg.Stake != nil: + _, stake := msg.Funds.Find(bondDenom) + sdkMsg, err = coreContractMsg.Stake.EncodeToSdkMsg(msg.Sender, stake) + + case coreContractMsg.PostDataRequest != nil: + _, funds := msg.Funds.Find(bondDenom) + sdkMsg, err = coreContractMsg.PostDataRequest.EncodeToSdkMsg(msg.Sender, funds) + + case coreContractMsg.CommitDataResult != nil: + sdkMsg, err = coreContractMsg.CommitDataResult.EncodeToSdkMsg(msg.Sender) + + case coreContractMsg.RevealDataResult != nil: + sdkMsg, err = coreContractMsg.RevealDataResult.EncodeToSdkMsg(msg.Sender) + + default: + // TODO Subject to change + return m.MsgServer.ExecuteContract(goCtx, msg) + } + if err != nil { + return nil, err + } + + handler := m.router.Handler(sdkMsg) + if handler == nil { + return nil, sdkerrors.ErrUnknownRequest.Wrapf("failed to find handler for message type %T", sdkMsg) + } + + result, err := handler(ctx, sdkMsg) + if err != nil { + return nil, err + } + + returnData := result.Data + if coreContractMsg.PostDataRequest != nil { + // Convert proto-encoded response to JSON. + var res coretypes.MsgPostDataRequestResponse + if err := res.Unmarshal(returnData); err != nil { + return nil, err + } + contractRes := &PostRequestResponsePayload{ + DrID: res.DrId, + //nolint:gosec // G115: Block height is never negative. + Height: uint64(res.Height), + } + returnData, err = json.Marshal(contractRes) + if err != nil { + return nil, err + } + } + + return &types.MsgExecuteContractResponse{ + Data: returnData, + }, nil +} diff --git a/x/wasm/msgs.go b/x/wasm/msgs.go new file mode 100644 index 00000000..e878939c --- /dev/null +++ b/x/wasm/msgs.go @@ -0,0 +1,178 @@ +package wasm + +import ( + "encoding/base64" + "encoding/hex" + "fmt" + + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" + + coretypes "github.com/sedaprotocol/seda-chain/x/core/types" +) + +func base64ToHex(base64Str string) (string, error) { + decoded, err := base64.StdEncoding.DecodeString(base64Str) + if err != nil { + return "", err + } + return hex.EncodeToString(decoded), nil +} + +type PostRequestResponsePayload struct { + DrID string `json:"dr_id"` + Height uint64 `json:"height"` +} + +type CoreContractMsg struct { + AddToAllowList *AddToAllowListMsg `json:"add_to_allowlist"` + Stake *StakeMsg `json:"stake"` + PostDataRequest *PostDataRequestMsg `json:"post_data_request"` + CommitDataResult *CommitDataResultMsg `json:"commit_data_result"` + RevealDataResult *RevealDataResultMsg `json:"reveal_data_result"` +} + +type AddToAllowListMsg struct { + PublicKey string `json:"public_key"` +} + +func (m AddToAllowListMsg) EncodeToSdkMsg(sender string) (sdk.Msg, error) { + return &coretypes.MsgAddToAllowlist{ + Sender: sender, // TODO ensure security + PublicKey: m.PublicKey, + }, nil +} + +type StakeMsg struct { + PublicKey string `json:"public_key"` + Proof string `json:"proof"` + Memo string `json:"memo"` +} + +func (m StakeMsg) EncodeToSdkMsg(sender string, stake sdk.Coin) (sdk.Msg, error) { + memoHex, err := base64ToHex(m.Memo) + if err != nil { + return nil, err + } + return &coretypes.MsgStake{ + Sender: sender, // TODO ensure security + PublicKey: m.PublicKey, + Proof: m.Proof, + Memo: memoHex, + Stake: stake, + }, nil +} + +type PostDataRequestMsg struct { + PostedDR PostedDR `json:"posted_dr"` + SedaPayload string `json:"seda_payload"` + PaybackAddress string `json:"payback_address"` +} + +type PostedDR struct { + Version string `json:"version"` + ExecProgramID string `json:"exec_program_id"` + ExecInputs string `json:"exec_inputs"` + ExecGasLimit uint64 `json:"exec_gas_limit"` + TallyProgramID string `json:"tally_program_id"` + TallyInputs string `json:"tally_inputs"` + TallyGasLimit uint64 `json:"tally_gas_limit"` + ReplicationFactor uint16 `json:"replication_factor"` + ConsensusFilter string `json:"consensus_filter"` + GasPrice string `json:"gas_price"` + Memo string `json:"memo"` +} + +func (m PostDataRequestMsg) EncodeToSdkMsg(sender string, funds sdk.Coin) (sdk.Msg, error) { + execInputs, err := base64.StdEncoding.DecodeString(m.PostedDR.ExecInputs) + if err != nil { + return nil, err + } + tallyInputs, err := base64.StdEncoding.DecodeString(m.PostedDR.TallyInputs) + if err != nil { + return nil, err + } + consensusFilter, err := base64.StdEncoding.DecodeString(m.PostedDR.ConsensusFilter) + if err != nil { + return nil, err + } + memo, err := base64.StdEncoding.DecodeString(m.PostedDR.Memo) + if err != nil { + return nil, err + } + sedaPayload, err := base64.StdEncoding.DecodeString(m.SedaPayload) + if err != nil { + return nil, err + } + paybackAddress, err := base64.StdEncoding.DecodeString(m.PaybackAddress) + if err != nil { + return nil, err + } + + gasPriceInt, ok := math.NewIntFromString(m.PostedDR.GasPrice) + if !ok { + return nil, fmt.Errorf("failed to convert gas price to big.Int") + } + + return &coretypes.MsgPostDataRequest{ + Sender: sender, + Funds: funds, + Version: m.PostedDR.Version, + ExecProgramId: m.PostedDR.ExecProgramID, + ExecInputs: execInputs, + ExecGasLimit: m.PostedDR.ExecGasLimit, + TallyProgramId: m.PostedDR.TallyProgramID, + TallyInputs: tallyInputs, + TallyGasLimit: m.PostedDR.TallyGasLimit, + ReplicationFactor: uint32(m.PostedDR.ReplicationFactor), + ConsensusFilter: consensusFilter, + GasPrice: gasPriceInt, + Memo: memo, + SEDAPayload: sedaPayload, + PaybackAddress: paybackAddress, + }, nil +} + +type CommitDataResultMsg struct { + DrID string `json:"dr_id"` + Commitment string `json:"commitment"` + PublicKey string `json:"public_key"` + Proof string `json:"proof"` +} + +func (m CommitDataResultMsg) EncodeToSdkMsg(sender string) (sdk.Msg, error) { + return &coretypes.MsgCommit{ + Sender: sender, // TODO ensure security + DrId: m.DrID, + Commit: m.Commitment, + PublicKey: m.PublicKey, + Proof: m.Proof, + }, nil +} + +type RevealDataResultMsg struct { + RevealBody coretypes.RevealBody `json:"reveal_body"` + PublicKey string `json:"public_key"` + Proof string `json:"proof"` + Stderr []string `json:"stderr"` + Stdout []string `json:"stdout"` +} + +func (m RevealDataResultMsg) EncodeToSdkMsg(sender string) (sdk.Msg, error) { + return &coretypes.MsgReveal{ + Sender: sender, // TODO ensure security + RevealBody: &coretypes.RevealBody{ + DrId: m.RevealBody.DrId, + DrBlockHeight: m.RevealBody.DrBlockHeight, + ExitCode: m.RevealBody.ExitCode, + GasUsed: m.RevealBody.GasUsed, + Reveal: m.RevealBody.Reveal, + ProxyPubKeys: m.RevealBody.ProxyPubKeys, + }, + PublicKey: m.PublicKey, + Proof: m.Proof, + Stderr: m.Stderr, + Stdout: m.Stdout, + }, nil +}