Skip to content

Commit

Permalink
fixing issues with keygeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
ap0calypse644 committed Aug 22, 2024
1 parent 9af7227 commit 0a6cd50
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 2,657 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ integration-test-all: init-test-framework \
devnet-up: init-devnet
@echo "Fairyring Devnet is now running in the background, run 'make devnet-down' to stop devnet."

devnet-down: clean-devnet-data
devnet-down:
@echo "Killing fairyringd, fairyport, fairyringclient, ShareGenerationClient and removing previous data"
-@killall fairyringd 2>/dev/null
-@killall fairyport 2>/dev/null
-@killall fairyringclient 2>/dev/null
-@killall ShareGenerationClient 2>/dev/null

test-tx-limit:
@echo "Testing Block tx limit..."
Expand Down
152 changes: 82 additions & 70 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package app

import (
"errors"

corestoretypes "cosmossdk.io/core/store"
circuitante "cosmossdk.io/x/circuit/ante"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand All @@ -13,17 +11,20 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
"github.com/skip-mev/block-sdk/v2/block"
)

type FairyringHandlerOptions struct {
BaseOptions ante.HandlerOptions
wasmConfig wasmtypes.WasmConfig
KeyShareLane pepante.KeyShareLane
FreeLane block.Lane
TxDecoder sdk.TxDecoder
TxEncoder sdk.TxEncoder
PepKeeper pepkeeper.Keeper
// FreeLane block.Lane
BaseOptions ante.HandlerOptions
KeyShareLane pepante.KeyShareLane
TxDecoder sdk.TxDecoder
TxEncoder sdk.TxEncoder
PepKeeper pepkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
CircuitKeeper circuitante.CircuitBreaker
}

// NewFairyringAnteHandler wraps all of the default Cosmos SDK AnteDecorators with the Fairyring AnteHandler.
Expand All @@ -44,85 +45,96 @@ func NewFairyringAnteHandler(options FairyringHandlerOptions) sdk.AnteHandler {
panic("fee grant keeper is required for ante builder")
}

if options.WasmConfig == nil {
panic("wasm config is required for ante builder")
}
if options.TXCounterStoreService == nil {
panic("wasm store service is required for ante builder")
}
if options.CircuitKeeper == nil {
panic("circuit keeper is required for ante builder")
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.wasmConfig.SimulationGasLimit),
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService),
wasmkeeper.NewGasRegisterDecorator(options.WasmKeeper.GetGasRegister()),
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
ante.NewExtensionOptionsDecorator(options.BaseOptions.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.BaseOptions.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.BaseOptions.AccountKeeper),
block.NewIgnoreDecorator(
ante.NewDeductFeeDecorator(
options.BaseOptions.AccountKeeper,
options.BaseOptions.BankKeeper,
options.BaseOptions.FeegrantKeeper,
options.BaseOptions.TxFeeChecker,
),
options.FreeLane,
ante.NewDeductFeeDecorator(
options.BaseOptions.AccountKeeper,
options.BaseOptions.BankKeeper,
options.BaseOptions.FeegrantKeeper,
options.BaseOptions.TxFeeChecker,
),
ante.NewSetPubKeyDecorator(options.BaseOptions.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.BaseOptions.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.BaseOptions.AccountKeeper, options.BaseOptions.SigGasConsumer),
ante.NewSigVerificationDecorator(options.BaseOptions.AccountKeeper, options.BaseOptions.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.BaseOptions.AccountKeeper),
pepante.NewPepDecorator(options.PepKeeper, options.TxEncoder, options.KeyShareLane),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
// pepante.NewPepDecorator(options.PepKeeper, options.TxEncoder, options.KeyShareLane),
}

return sdk.ChainAnteDecorators(anteDecorators...)
}

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions
// // HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// // channel keeper.
// type HandlerOptions struct {
// ante.HandlerOptions

IBCKeeper *ibckeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
WasmKeeper *wasmkeeper.Keeper
TXCounterStoreService corestoretypes.KVStoreService
CircuitKeeper circuitante.CircuitBreaker
}
// IBCKeeper *ibckeeper.Keeper
// WasmConfig *wasmtypes.WasmConfig
// WasmKeeper *wasmkeeper.Keeper
// TXCounterStoreService corestoretypes.KVStoreService
// CircuitKeeper circuitante.CircuitBreaker
// }

func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, errors.New("account keeper is required for ante builder")
}
if options.BankKeeper == nil {
return nil, errors.New("bank keeper is required for ante builder")
}
if options.SignModeHandler == nil {
return nil, errors.New("sign mode handler is required for ante builder")
}
if options.WasmConfig == nil {
return nil, errors.New("wasm config is required for ante builder")
}
if options.TXCounterStoreService == nil {
return nil, errors.New("wasm store service is required for ante builder")
}
if options.CircuitKeeper == nil {
return nil, errors.New("circuit keeper is required for ante builder")
}
// func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
// if options.AccountKeeper == nil {
// return nil, errors.New("account keeper is required for ante builder")
// }
// if options.BankKeeper == nil {
// return nil, errors.New("bank keeper is required for ante builder")
// }
// if options.SignModeHandler == nil {
// return nil, errors.New("sign mode handler is required for ante builder")
// }
// if options.WasmConfig == nil {
// return nil, errors.New("wasm config is required for ante builder")
// }
// if options.TXCounterStoreService == nil {
// return nil, errors.New("wasm store service is required for ante builder")
// }
// if options.CircuitKeeper == nil {
// return nil, errors.New("circuit keeper is required for ante builder")
// }

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService),
wasmkeeper.NewGasRegisterDecorator(options.WasmKeeper.GetGasRegister()),
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
}
// anteDecorators := []sdk.AnteDecorator{
// ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
// wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early
// wasmkeeper.NewCountTXDecorator(options.TXCounterStoreService),
// wasmkeeper.NewGasRegisterDecorator(options.WasmKeeper.GetGasRegister()),
// circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
// ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
// ante.NewValidateBasicDecorator(),
// ante.NewTxTimeoutHeightDecorator(),
// ante.NewValidateMemoDecorator(options.AccountKeeper),
// ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
// ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
// ante.NewValidateSigCountDecorator(options.AccountKeeper),
// ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
// ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
// ante.NewIncrementSequenceDecorator(options.AccountKeeper),
// ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
// }

return sdk.ChainAnteDecorators(anteDecorators...), nil
}
// return sdk.ChainAnteDecorators(anteDecorators...), nil
// }
49 changes: 27 additions & 22 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package app

import (
"context"
circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/nft"
upgradetypes "cosmossdk.io/x/upgrade/types"
"fmt"
feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
"io"
"os"
"path/filepath"

circuittypes "cosmossdk.io/x/circuit/types"
"cosmossdk.io/x/nft"
upgradetypes "cosmossdk.io/x/upgrade/types"
feetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"

_ "cosmossdk.io/api/cosmos/tx/config/v1" // import for side-effects
"cosmossdk.io/depinject"
"cosmossdk.io/log"
Expand All @@ -27,6 +28,7 @@ import (
upgradekeeper "cosmossdk.io/x/upgrade/keeper"
"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/Fairblock/fairyring/abci/checktx"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
dbm "github.com/cosmos/cosmos-db"
Expand Down Expand Up @@ -349,18 +351,23 @@ func New(

app.App = appBuilder.Build(db, traceStore, baseAppOptions...)

// Register legacy modules
if err := app.registerIBCModules(appOpts); err != nil {
return nil, err
}

// ---------------------------------------------------------------------------- //
// ------------------------- Begin Custom Code -------------------------------- //
// ---------------------------------------------------------------------------- //
// STEP 1-3: Create the Block SDK lanes.
keyshareLane, freeLane, defaultLane := CreateLanes(app)
keyshareLane, defaultLane := CreateLanes(app)

// STEP 4: Construct a mempool based off the lanes. Note that the order of the lanes
// matters. Blocks are constructed from the top lane to the bottom lane. The top lane
// is the first lane in the array and the bottom lane is the last lane in the array.
mempool, err := block.NewLanedMempool(
app.Logger(),
[]block.Lane{keyshareLane, freeLane, defaultLane},
[]block.Lane{keyshareLane, defaultLane},
)
if err != nil {
panic(err)
Expand All @@ -385,13 +392,16 @@ func New(
SignModeHandler: app.txConfig.SignModeHandler(),
}
options := FairyringHandlerOptions{
BaseOptions: handlerOptions,
wasmConfig: wasmConfig,
TxDecoder: app.txConfig.TxDecoder(),
TxEncoder: app.txConfig.TxEncoder(),
KeyShareLane: keyshareLane,
PepKeeper: app.PepKeeper,
FreeLane: freeLane,
BaseOptions: handlerOptions,
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
WasmKeeper: &app.WasmKeeper,
TXCounterStoreService: runtime.NewKVStoreService(app.GetKey(wasmtypes.StoreKey)),
CircuitKeeper: &app.CircuitBreakerKeeper,
TxDecoder: app.txConfig.TxDecoder(),
TxEncoder: app.txConfig.TxEncoder(),
KeyShareLane: keyshareLane,
PepKeeper: app.PepKeeper,
}
anteHandler := NewFairyringAnteHandler(options)
app.App.SetAnteHandler(anteHandler)
Expand All @@ -403,12 +413,12 @@ func New(
keyshareLane.WithOptions(
opt...,
)
freeLane.WithOptions(
opt...,
)
// defaultLane.WithOptions(
// freeLane.WithOptions(
// opt...,
// )
defaultLane.WithOptions(
opt...,
)

// Step 6: Create the proposal handler and set it on the app. Now the application
// will build and verify proposals using the Block SDK!
Expand Down Expand Up @@ -441,11 +451,6 @@ func New(
// ------------------------- End Custom Code ---------------------------------- //
// ---------------------------------------------------------------------------- //

// Register legacy modules
if err := app.registerIBCModules(appOpts); err != nil {
return nil, err
}

// register streaming services
if err := app.RegisterStreamingServices(appOpts, app.kvStoreKeys()); err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 0a6cd50

Please sign in to comment.