Skip to content

Commit

Permalink
Merge pull request #184 from Fairblock/v0.8.2-fix
Browse files Browse the repository at this point in the history
fixing issues with keygeneration
  • Loading branch information
p0p3yee authored Aug 22, 2024
2 parents a6f61a7 + 90988fd commit 5f889a0
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 2,653 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
// }
45 changes: 27 additions & 18 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"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 @@ -24,6 +29,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 @@ -346,18 +352,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 @@ -382,13 +393,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 @@ -400,12 +414,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 @@ -438,11 +452,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
41 changes: 20 additions & 21 deletions app/lanes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
signerextraction "github.com/skip-mev/block-sdk/v2/adapters/signer_extraction_adapter"
"github.com/skip-mev/block-sdk/v2/block/base"
defaultlane "github.com/skip-mev/block-sdk/v2/lanes/base"
freelane "github.com/skip-mev/block-sdk/v2/lanes/free"
)

// CreateLanes walks through the process of creating the lanes for the block sdk. In this function
// we create three separate lanes - Keyshare, Free, and Default - and then return them.
//
// NOTE: Application Developers should closely replicate this function in their own application.
func CreateLanes(app *App) (*keysharelane.KeyShareLane, *base.BaseLane, *base.BaseLane) {
func CreateLanes(app *App) (*keysharelane.KeyShareLane, *base.BaseLane) {
// 1. Create the signer extractor. This is used to extract the expected signers from
// a transaction. Each lane can have a different signer extractor if needed.
signerAdapter := signerextraction.NewDefaultAdapter()
Expand All @@ -32,31 +31,31 @@ func CreateLanes(app *App) (*keysharelane.KeyShareLane, *base.BaseLane, *base.Ba
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.3"),
SignerExtractor: signerAdapter,
MaxTxs: 1000,
MaxTxs: 10000,
}

// Create a free configuration that accepts 1000 transactions and consumes 20% of the
// block space.
freeConfig := base.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
SignerExtractor: signerAdapter,
MaxTxs: 1000,
}
// freeConfig := base.LaneConfig{
// Logger: app.Logger(),
// TxEncoder: app.txConfig.TxEncoder(),
// TxDecoder: app.txConfig.TxDecoder(),
// MaxBlockSpace: math.LegacyMustNewDecFromStr("0.2"),
// SignerExtractor: signerAdapter,
// MaxTxs: 1000,
// }

// Create a default configuration that accepts 1000 transactions and consumes 60% of the
// block space.
defaultConfig := base.LaneConfig{
Logger: app.Logger(),
TxEncoder: app.txConfig.TxEncoder(),
TxDecoder: app.txConfig.TxDecoder(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.6"),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.7"),
SignerExtractor: signerAdapter,
MaxTxs: 1000,
MaxTxs: 10000,
}

// 3. Create the match handlers for each lane. These match handlers determine whether or not
Expand All @@ -67,7 +66,7 @@ func CreateLanes(app *App) (*keysharelane.KeyShareLane, *base.BaseLane, *base.Ba
keyshareMatchHandler := factory.MatchHandler()

// Create the final match handler for the free lane.
freeMatchHandler := freelane.DefaultMatchHandler()
// freeMatchHandler := freelane.DefaultMatchHandler()

// Create the final match handler for the default lane.
defaultMatchHandler := base.DefaultMatchHandler()
Expand All @@ -79,16 +78,16 @@ func CreateLanes(app *App) (*keysharelane.KeyShareLane, *base.BaseLane, *base.Ba
keyshareMatchHandler,
)

freeLane := freelane.NewFreeLane(
freeConfig,
base.DefaultTxPriority(),
freeMatchHandler,
)
// freeLane := freelane.NewFreeLane(
// freeConfig,
// base.DefaultTxPriority(),
// freeMatchHandler,
// )

defaultLane := defaultlane.NewDefaultLane(
defaultConfig,
defaultMatchHandler,
)

return keyshareLane, freeLane, defaultLane
return keyshareLane, defaultLane
}
Loading

0 comments on commit 5f889a0

Please sign in to comment.