Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small optimisations (cosmos#261)
Browse files Browse the repository at this point in the history
* mutex don't cover GetSigners

don't clone header in context

* Update CHANGELOG.md

Signed-off-by: yihuang <huang@crypto.com>

* update comment

---------

Signed-off-by: yihuang <huang@crypto.com>
yihuang authored and mmsqe committed Dec 14, 2024

Verified

This commit was signed with the committer’s verified signature.
mmsqe mmsqe
1 parent 378bf60 commit afb5648
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions types/context.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -111,10 +110,9 @@ func (c Context) TxCount() int { return c.txCou
func (c Context) BlockGasUsed() uint64 { return c.blockGasUsed }
func (c Context) BlockGasWanted() uint64 { return c.blockGasWanted }

// clone the header before returning
// BlockHeader returns the header by value (shallow copy).
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
5 changes: 3 additions & 2 deletions types/mempool/priority_nonce.go
Original file line number Diff line number Diff line change
@@ -444,8 +444,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
@@ -458,6 +456,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 {

0 comments on commit afb5648

Please sign in to comment.