mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-01 14:26:02 +00:00
handle error if account is meeting for the first time.
This commit is contained in:
parent
2cc584be0b
commit
4c48f7ea63
24
app/app.go
24
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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user