Skip to content

Commit

Permalink
sgdindexer performance improvement (#4148)
Browse files Browse the repository at this point in the history
Co-authored-by: Haaai <55118568+Liuhaai@users.noreply.github.com>
  • Loading branch information
millken and Liuhaai authored Feb 26, 2024
1 parent fa9185c commit 7f35898
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions blockindex/sgd_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-proto/golang/iotextypes"
"github.com/pkg/errors"
Expand Down Expand Up @@ -292,19 +291,10 @@ func (sgd *sgdRegistry) PutBlock(ctx context.Context, blk *block.Block) error {
return errors.Errorf("invalid block height %d, expect %d", blk.Height(), expectHeight)
}

var (
r *action.Receipt
ok bool
b = batch.NewBatch()
)
receipts := getReceiptsFromBlock(blk)
for _, selp := range blk.Actions {
actHash, err := selp.Hash()
if err != nil {
continue
}
r, ok = receipts[actHash]
if !ok || r.Status != uint64(iotextypes.ReceiptStatus_Success) {
var b = batch.NewBatch()

for _, r := range blk.Receipts {
if r.Status != uint64(iotextypes.ReceiptStatus_Success) {
continue
}
for _, log := range r.Logs() {
Expand Down Expand Up @@ -533,11 +523,3 @@ func (sgd *sgdRegistry) height() (uint64, error) {
}
return byteutil.BytesToUint64BigEndian(h), nil
}

func getReceiptsFromBlock(blk *block.Block) map[hash.Hash256]*action.Receipt {
receipts := make(map[hash.Hash256]*action.Receipt, len(blk.Receipts))
for _, receipt := range blk.Receipts {
receipts[receipt.ActionHash] = receipt
}
return receipts
}

0 comments on commit 7f35898

Please sign in to comment.