Skip to content

Commit

Permalink
fix: panic on contract deployment (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
byte-bandit authored Dec 4, 2023
1 parent 72fcb67 commit 16d7896
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
8 changes: 5 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ func New(
app.ValsetKeeper,
)
app.ValsetKeeper.SnapshotListeners = []valsetmoduletypes.OnSnapshotBuiltListener{
app.EvmKeeper,
&app.EvmKeeper,
}
app.ValsetKeeper.EvmKeeper = app.EvmKeeper

Expand All @@ -571,7 +571,9 @@ func New(
gravitymodulekeeper.NewGravityStoreGetter(keys[gravitymoduletypes.StoreKey]),
)
// TODO: Use proper dependency resolution instead of
// this abomination
// this abomination.
// TODO: Refactor app to use pointer values only instead
// of keeping value copies and blowing up the stack.
app.EvmKeeper.Gravity = app.GravityKeeper

app.PalomaKeeper = *palomamodulekeeper.NewKeeper(
Expand Down Expand Up @@ -739,7 +741,7 @@ func New(
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.

evmModule := evm.NewAppModule(appCodec, app.EvmKeeper, app.AccountKeeper, app.BankKeeper)
evmModule := evm.NewAppModule(appCodec, app.EvmKeeper)
consensusModule := consensusmodule.NewAppModule(appCodec, app.ConsensusKeeper, app.AccountKeeper, app.BankKeeper)
valsetModule := valsetmodule.NewAppModule(appCodec, app.ValsetKeeper, app.AccountKeeper, app.BankKeeper)
schedulerModule := schedulermodule.NewAppModule(appCodec, app.SchedulerKeeper, app.AccountKeeper, app.BankKeeper)
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func init() {
}
}

var _ valsettypes.OnSnapshotBuiltListener = Keeper{}
var _ valsettypes.OnSnapshotBuiltListener = &Keeper{}

type Keeper struct {
cdc codec.BinaryCodec
Expand Down Expand Up @@ -534,7 +534,7 @@ func (k Keeper) PublishSnapshotToAllChains(ctx sdk.Context, snapshot *valsettype
return nil
}

func (k Keeper) OnSnapshotBuilt(ctx sdk.Context, snapshot *valsettypes.Snapshot) {
func (k *Keeper) OnSnapshotBuilt(ctx sdk.Context, snapshot *valsettypes.Snapshot) {
err := k.PublishSnapshotToAllChains(ctx, snapshot, false)
if err != nil {
panic(err)
Expand Down
9 changes: 6 additions & 3 deletions x/evm/keeper/smart_contract_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ func (k Keeper) deploySmartContractToChain(ctx sdk.Context, chainInfo *types.Cha
args = append(args, "err", retErr)
}

if r := recover(); r != nil {
args = append(args, "panic", r)
k.Logger(ctx).Error("recovered panic! Error adding a message to deploy smart contract to chain", args...)
}

if retErr != nil {
k.Logger(ctx).Error("error adding a message to deploy smart contract to chain", args...)
} else {
Expand Down Expand Up @@ -229,21 +234,19 @@ func (k Keeper) deploySmartContractToChain(ctx sdk.Context, chainInfo *types.Cha
uniqueID := generateSmartContractID(ctx)

k.createSmartContractDeployment(ctx, smartContract, chainInfo, uniqueID[:])

lastEventNonce, err := k.Gravity.GetLastObservedEventNonce(ctx)
if err != nil {
return fmt.Errorf("failed to get last observed event nonce: %w", err)
}

// set the smart contract constructor arguments
input, err := contractABI.Pack("", uniqueID, (&big.Int{}).SetUint64(lastEventNonce), types.TransformValsetToABIValset(valset))

logger.Info(
"transform valset to abi valset",
"valset-id", valset.GetValsetID(),
"validators-size", len(valset.GetValidators()),
"power-size", len(valset.GetPowers()),
)
input, err := contractABI.Pack("", uniqueID, (&big.Int{}).SetUint64(lastEventNonce), types.TransformValsetToABIValset(valset))
if err != nil {
return err
}
Expand Down
8 changes: 1 addition & 7 deletions x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,16 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command {
type AppModule struct {
AppModuleBasic

keeper keeper.Keeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
keeper keeper.Keeper
}

func NewAppModule(
cdc codec.Codec,
keeper keeper.Keeper,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
) AppModule {
return AppModule{
AppModuleBasic: NewAppModuleBasic(cdc),
keeper: keeper,
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
}
}

Expand Down

0 comments on commit 16d7896

Please sign in to comment.