mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-04-04 15:55:23 +00:00
Compare commits
3 Commits
5af413f6b3
...
68d3c78e7e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
68d3c78e7e | ||
![]() |
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 {
|
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)
|
acc := ano.ak.GetAccount(ctx, bzAcc)
|
||||||
|
if acc == nil {
|
||||||
|
ctx.Logger().Error("GetAccountNonce: account not found", "address", address)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return acc.GetSequence()
|
return acc.GetSequence()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ano *accountNonceOp) SetAccountNonce(ctx sdk.Context, address string, nonce uint64) {
|
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 := ano.ak.GetAccount(ctx, bzAcc)
|
||||||
acc.SetSequence(nonce)
|
if acc != nil {
|
||||||
ano.ak.SetAccount(ctx, acc)
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if indexSize > 1 {
|
if indexSize > 0 {
|
||||||
tail := index.Back()
|
tail := index.Back()
|
||||||
if tail != nil {
|
if tail != nil {
|
||||||
tailKey := tail.Key().(txMeta)
|
tailKey := tail.Key().(txMeta)
|
||||||
@ -291,8 +291,6 @@ func (mp *PriorityNonceMempool) Insert(ctx context.Context, tx sdk.Tx) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} 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)
|
return errors.Wrapf(errMempoolIsFull, "%d@%s with priority%d", newKey.nonce, newKey.sender, newKey.priority)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -137,8 +137,12 @@ func (ac appCreator) newApp(
|
|||||||
sdkContext := sdk.UnwrapSDKContext(ctx)
|
sdkContext := sdk.UnwrapSDKContext(ctx)
|
||||||
if accountNonceOp != nil {
|
if accountNonceOp != nil {
|
||||||
nonce := accountNonceOp.GetAccountNonce(sdkContext, oldTx.Sender)
|
nonce := accountNonceOp.GetAccountNonce(sdkContext, oldTx.Sender)
|
||||||
accountNonceOp.SetAccountNonce(sdkContext, oldTx.Sender, nonce-1)
|
if nonce > 0 {
|
||||||
sdkContext.Logger().Debug("rewind the nonce of the account", "account", oldTx.Sender, "from", nonce, "to", nonce-1)
|
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 {
|
} else {
|
||||||
sdkContext := sdk.UnwrapSDKContext(ctx)
|
sdkContext := sdk.UnwrapSDKContext(ctx)
|
||||||
|
Loading…
Reference in New Issue
Block a user