From 8c5d15521da143086be4733fe57946043b6fc87b Mon Sep 17 00:00:00 2001 From: Mark Cherepovskyi Date: Fri, 30 Aug 2024 13:47:26 +0300 Subject: [PATCH 1/2] logs and update handler --- app/app.go | 7 +++++++ x/rootupdater/keeper/abci.go | 3 +++ x/rootupdater/keeper/keeper.go | 23 +++++++++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/app.go b/app/app.go index 1f09dea8..4c8fc7be 100644 --- a/app/app.go +++ b/app/app.go @@ -1133,6 +1133,13 @@ func New( }, ) + app.UpgradeKeeper.SetUpgradeHandler( + "v1.1.4-rc3", + func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return app.mm.RunMigrations(ctx, app.configurator, fromVM) + }, + ) + if loadLatest { if err := app.LoadLatestVersion(); err != nil { tmos.Exit(err.Error()) diff --git a/x/rootupdater/keeper/abci.go b/x/rootupdater/keeper/abci.go index 22dd46ae..6d7442e8 100644 --- a/x/rootupdater/keeper/abci.go +++ b/x/rootupdater/keeper/abci.go @@ -10,9 +10,12 @@ func (k Keeper) EndBlocker(ctx sdk.Context) { params := k.GetParams(ctx) if params.Root == params.LastSignedRoot && params.Root != "" { + k.Logger(ctx).Info("root is not updated. Skipping end block") return } + k.Logger(ctx).Info("root is updated. Operation creating") + // Creating operation to be signed by TSS parties index, err := k.rarimo.CreateRootUpdateOperation(ctx, types.ModuleName, &rarimocoremoduletypes.PassportRootUpdate{ ContractAddress: params.ContractAddress, diff --git a/x/rootupdater/keeper/keeper.go b/x/rootupdater/keeper/keeper.go index 82748759..012ae300 100644 --- a/x/rootupdater/keeper/keeper.go +++ b/x/rootupdater/keeper/keeper.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common/hexutil" @@ -57,39 +58,53 @@ func NewKeeper( func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error { params := k.GetParams(ctx) + k.Logger(ctx).Error("PostTxProcessing", "msg", msg, "receipt", receipt) + stateV2, err := abi.JSON(strings.NewReader(state.PoseidonSMTABI)) if err != nil { + k.Logger(ctx).Error("failed to marshal poseidon smart abi", "error", err) return err } contractAddress, err := hexutil.Decode(params.ContractAddress) if err != nil { // If return an error here, the whole EVM module won't work - k.Logger(ctx).Debug("failed to decode contract address") + k.Logger(ctx).Info("failed to decode contract address") return nil } // Validating message receiver address (should be our state smart contract) if msg.To() == nil || bytes.Compare(msg.To().Bytes(), contractAddress) != 0 { + k.Logger(ctx).Info("inappropriate contract address") return nil } + var commonError error // https://docs.evmos.org/protocol/modules/evm#posttxprocessing + + if len(receipt.Logs) == 0 { + k.Logger(ctx).Error("logs is empty") + } + for _, log := range receipt.Logs { eventId := log.Topics[0] - event, err := stateV2.EventByID(eventId) if err != nil { + k.Logger(ctx).Error("failed to get event by ID") + commonError = errors.Wrap(commonError, errors.Wrapf(err, "failed to get event by id %s", eventId).Error()) continue } if event.Name != params.EventName { + k.Logger(ctx).Info("unmatched event: got %s, expected %s", event.Name, params.EventName) continue } eventBody := state.PoseidonSMTRootUpdated{} if err := utils.UnpackLog(stateV2, &eventBody, event.Name, log); err != nil { - return err + k.Logger(ctx).Error("failed to unpack event body") + commonError = errors.Wrap(commonError, errors.Wrapf(err, "failed to unpack event %s", eventId).Error()) + continue } params.Root = hexutil.Encode(eventBody.Root[:]) @@ -100,7 +115,7 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth k.SetParams(ctx, params) } - return nil + return commonError } func (k Keeper) Logger(ctx sdk.Context) log.Logger { From 954d3c0cb1036ced1d0c56f24b345544147afdee Mon Sep 17 00:00:00 2001 From: Mark Cherepovskyi Date: Fri, 30 Aug 2024 14:43:32 +0300 Subject: [PATCH 2/2] remove common error --- x/rootupdater/keeper/keeper.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/x/rootupdater/keeper/keeper.go b/x/rootupdater/keeper/keeper.go index 012ae300..4dc5b89b 100644 --- a/x/rootupdater/keeper/keeper.go +++ b/x/rootupdater/keeper/keeper.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common/hexutil" @@ -79,7 +78,6 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth return nil } - var commonError error // https://docs.evmos.org/protocol/modules/evm#posttxprocessing if len(receipt.Logs) == 0 { @@ -91,7 +89,6 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth event, err := stateV2.EventByID(eventId) if err != nil { k.Logger(ctx).Error("failed to get event by ID") - commonError = errors.Wrap(commonError, errors.Wrapf(err, "failed to get event by id %s", eventId).Error()) continue } @@ -103,7 +100,6 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth eventBody := state.PoseidonSMTRootUpdated{} if err := utils.UnpackLog(stateV2, &eventBody, event.Name, log); err != nil { k.Logger(ctx).Error("failed to unpack event body") - commonError = errors.Wrap(commonError, errors.Wrapf(err, "failed to unpack event %s", eventId).Error()) continue } @@ -115,7 +111,7 @@ func (k Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *eth k.SetParams(ctx, params) } - return commonError + return nil } func (k Keeper) Logger(ctx sdk.Context) log.Logger {