diff --git a/app/app.go b/app/app.go index 832a822a..d148e857 100644 --- a/app/app.go +++ b/app/app.go @@ -1085,14 +1085,30 @@ func NewAccountNonceOp(app *App) AccountNonceOp { } func (ano *accountNonceOp) GetAccountNonce(ctx sdk.Context, address string) uint64 { - bzAcc, _ := sdk.AccAddressFromBech32(address) + bzAcc, err := sdk.AccAddressFromBech32(address) + if err != nil { + ctx.Logger().Error("GetAccountNonce: failed to parse address", "address", address, "error", err) + return 0 + } acc := ano.ak.GetAccount(ctx, bzAcc) + if acc == nil { + ctx.Logger().Error("GetAccountNonce: account not found", "address", address) + return 0 + } return acc.GetSequence() } func (ano *accountNonceOp) SetAccountNonce(ctx sdk.Context, address string, nonce uint64) { - bzAcc, _ := sdk.AccAddressFromBech32(address) + bzAcc, err := sdk.AccAddressFromBech32(address) + if err != nil { + ctx.Logger().Error("SetAccountNonce: failed to parse address", "address", address, "nonce", nonce, "error", err) + return + } acc := ano.ak.GetAccount(ctx, bzAcc) - acc.SetSequence(nonce) - ano.ak.SetAccount(ctx, acc) + if acc != nil { + acc.SetSequence(nonce) + ano.ak.SetAccount(ctx, acc) + } else { + ctx.Logger().Error("SetAccountNonce: account not found", "address", address) + } } diff --git a/cmd/0gchaind/app.go b/cmd/0gchaind/app.go index 39bcdd49..a2c7ea4d 100644 --- a/cmd/0gchaind/app.go +++ b/cmd/0gchaind/app.go @@ -137,8 +137,12 @@ func (ac appCreator) newApp( sdkContext := sdk.UnwrapSDKContext(ctx) if accountNonceOp != nil { nonce := accountNonceOp.GetAccountNonce(sdkContext, oldTx.Sender) - accountNonceOp.SetAccountNonce(sdkContext, oldTx.Sender, nonce-1) - sdkContext.Logger().Debug("rewind the nonce of the account", "account", oldTx.Sender, "from", nonce, "to", nonce-1) + if nonce > 0 { + accountNonceOp.SetAccountNonce(sdkContext, oldTx.Sender, nonce-1) + sdkContext.Logger().Debug("rewind the nonce of the account", "account", oldTx.Sender, "from", nonce, "to", nonce-1) + } else { + sdkContext.Logger().Info("First meeting account", "account", oldTx.Sender) + } } } else { sdkContext := sdk.UnwrapSDKContext(ctx)