Skip to content

Commit

Permalink
mutex don't cover GetSigners
Browse files Browse the repository at this point in the history
don't clone header in context
  • Loading branch information
yihuang committed Apr 8, 2024
1 parent 0bb12ec commit f6feb5c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#248](https://github.com/crypto-org-chain/cosmos-sdk/pull/248) Init btree store lazily to save allocations when no content insert into it.
* [#252](https://github.com/crypto-org-chain/cosmos-sdk/pull/252) Add `BlockGasWanted` to `Context` to support feemarket module.

### Improvements

* [#]() `ctx.BlockHeader` don't do protobuf deep copy, shallow copy seems enough, reduce scope of mutex in `PriorityNonceMempool.Remove`.

## [Unreleased-Upstream]

### Bug Fixes
Expand Down
4 changes: 1 addition & 3 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/core/comet"
"cosmossdk.io/core/header"
Expand Down Expand Up @@ -111,8 +110,7 @@ func (c Context) BlockGasWanted() uint64 { return c.block

// clone the header before returning
func (c Context) BlockHeader() cmtproto.Header {
msg := proto.Clone(&c.header).(*cmtproto.Header)
return *msg
return c.header
}

// HeaderHash returns a copy of the header hash obtained during abci.RequestBeginBlock
Expand Down
5 changes: 3 additions & 2 deletions types/mempool/priority_nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ func (mp *PriorityNonceMempool[C]) CountTx() int {
// Remove removes a transaction from the mempool in O(log n) time, returning an
// error if unsuccessful.
func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
mp.mtx.Lock()
defer mp.mtx.Unlock()
sigs, err := mp.cfg.SignerExtractor.GetSigners(tx)
if err != nil {
return err
Expand All @@ -443,6 +441,9 @@ func (mp *PriorityNonceMempool[C]) Remove(tx sdk.Tx) error {
sender := sig.Signer.String()
nonce := sig.Sequence

mp.mtx.Lock()
defer mp.mtx.Unlock()

scoreKey := txMeta[C]{nonce: nonce, sender: sender}
score, ok := mp.scores[scoreKey]
if !ok {
Expand Down

0 comments on commit f6feb5c

Please sign in to comment.