Skip to content

Commit

Permalink
cache stx id
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Sep 18, 2024
1 parent 9b9902f commit ae1ba90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions data/transactions/signedtxn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type SignedTxn struct {
Lsig LogicSig `codec:"lsig"`
Txn Transaction `codec:"txn"`
AuthAddr basics.Address `codec:"sgnr"`

cachedID *Txid
}

// SignedTxnInBlock is how a signed transaction is encoded in a block.
Expand All @@ -59,9 +61,17 @@ type SignedTxnWithAD struct {

// ID returns the Txid (i.e., hash) of the underlying transaction.
func (s SignedTxn) ID() Txid {
if s.cachedID != nil {
return *s.cachedID
}
return s.Txn.ID()
}

func (s *SignedTxn) CacheID() {

Check failure on line 70 in data/transactions/signedtxn.go

View workflow job for this annotation

GitHub Actions / reviewdog-errors

[Lint Errors] reported by reviewdog 🐶 exported: exported method SignedTxn.CacheID should have comment or be unexported (revive) Raw Output: data/transactions/signedtxn.go:70:1: exported: exported method SignedTxn.CacheID should have comment or be unexported (revive) func (s *SignedTxn) CacheID() { ^
txid := s.Txn.ID()
s.cachedID = &txid
}

// ID on SignedTxnInBlock should never be called, because the ID depends
// on the block from which this transaction will be decoded. By having
// a different return value from SignedTxn.ID(), we will catch errors at
Expand Down
5 changes: 5 additions & 0 deletions data/txHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ func (handler *TxHandler) postProcessCheckedTxn(wi *txBacklogMsg) {
// at this point, we've verified the transaction, so we can safely treat the transaction as a verified transaction.
verifiedTxGroup := wi.unverifiedTxGroup

// precompute transaction IDs
for i := range verifiedTxGroup {
verifiedTxGroup[i].CacheID()
}

// save the transaction, if it has high enough fee and not already in the cache
err := handler.txPool.Remember(verifiedTxGroup)
if err != nil {
Expand Down

0 comments on commit ae1ba90

Please sign in to comment.