mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-04 15:55:23 +00:00
Compare commits
2 Commits
2cc584be0b
...
2c436a7d45
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2c436a7d45 | ||
![]() |
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)
|
||||
}
|
||||
}
|
||||
|
@ -258,7 +258,7 @@ func (mp *PriorityNonceMempool) Insert(ctx context.Context, tx sdk.Tx) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if indexSize > 1 {
|
||||
if indexSize > 0 {
|
||||
tail := index.Back()
|
||||
if tail != nil {
|
||||
tailKey := tail.Key().(txMeta)
|
||||
@ -291,8 +291,6 @@ func (mp *PriorityNonceMempool) Insert(ctx context.Context, tx sdk.Tx) error {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// not found any index more than 1 except sender's index
|
||||
// We do not replace the sender's only tx in the mempool
|
||||
return errors.Wrapf(errMempoolIsFull, "%d@%s with priority%d", newKey.nonce, newKey.sender, newKey.priority)
|
||||
}
|
||||
} else {
|
||||
|
@ -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