Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(BEDS-536): add re-index-blocks cmd to fix internal transfers status #2965

Merged
merged 47 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
190f40e
fix(internal transaction): recursively revert traces
Tangui-Bitfly Oct 1, 2024
43144fb
fix: SQLReaderDb interface missing methods
Tangui-Bitfly Oct 2, 2024
24087a7
fix(eth1tx): remove transfers if reverted
Tangui-Bitfly Oct 2, 2024
5a4c542
fix(internal tx): only save the highest root revert
Tangui-Bitfly Oct 2, 2024
983aea0
ci lint
Tangui-Bitfly Oct 2, 2024
19e6108
feat: updated eth1 proto file
Monika-Bitfly Oct 4, 2024
a2d8210
feat: updated Eth1InternalTransaction in eth1.proto file
Monika-Bitfly Oct 4, 2024
542bc39
feat: added Reverted value to Eth1InternalTransactionIndexed
Monika-Bitfly Oct 4, 2024
22303e9
feat: add check for internal txs while querying the block from erigon…
Monika-Bitfly Oct 4, 2024
3ec42b9
feat: updated reverted internal txs check logic
Monika-Bitfly Oct 4, 2024
bb1d8ab
feat(types): add status enum and add status partially executed
Tangui-Bitfly Oct 7, 2024
bb5ec81
refactor(client/erigon): simplify transaction indexing flow
Tangui-Bitfly Oct 7, 2024
1127a6f
feat(client/erigon): rework geth traces
Tangui-Bitfly Oct 7, 2024
c1a27cd
fix: lint
Tangui-Bitfly Oct 7, 2024
2a0a2fa
feat: add status to Eth1TransactionIndexed msg and update hash format…
Monika-Bitfly Oct 7, 2024
87bc9a3
fix: updated internal tx handling in GetBlock func
Monika-Bitfly Oct 7, 2024
93e492a
fix: updated internal txs parsing in GetBlock
Monika-Bitfly Oct 8, 2024
793b638
fix: optimise the memory of internla tx parsing
Monika-Bitfly Oct 8, 2024
12aba2f
Merge branch 'BEDS-536/fix-internal-transfers-display' of github.com:…
Monika-Bitfly Oct 8, 2024
057c25d
lint
Tangui-Bitfly Oct 8, 2024
abaaae2
fix(internal): remove revert + status logic from client to transformers
Tangui-Bitfly Oct 9, 2024
0dcaa74
test(internal): test for revert transformer on tx and itx
Tangui-Bitfly Oct 9, 2024
9ad4dde
feat(cmd): add re-index-blocks cmd
Tangui-Bitfly Oct 10, 2024
acd149d
chore(proto): clean proto Eth1Transaction and Eth1TransactionIndexed
Tangui-Bitfly Oct 10, 2024
5c033fa
fix(TransformItx): empty revertSource + error before skipping
Tangui-Bitfly Oct 10, 2024
20a211e
feat(BEDS-536): implement misc `fix-internal-txs-from-node` cmd with …
Monika-Bitfly Oct 23, 2024
357057a
(BEDS-536) Use raw db for resync (#2972)
Tangui-Bitfly Oct 29, 2024
34ce72c
fix ci
Tangui-Bitfly Oct 29, 2024
02926ed
store/bigtable: fix range limits
Tangui-Bitfly Oct 30, 2024
e4883a5
store/bigtable: fix grpc error on close
Tangui-Bitfly Oct 30, 2024
e272839
updated Receipts len check
Monika-Bitfly Oct 30, 2024
335b29c
updated traceMode to geth
Monika-Bitfly Oct 30, 2024
33eb338
fix ci
Tangui-Bitfly Oct 30, 2024
c14af4b
clenup
Monika-Bitfly Oct 30, 2024
6bb6221
rpc/erigon: parse traces geth handle CALLCODE
Tangui-Bitfly Nov 4, 2024
7056058
fix(transform itx): allow internal index == ITX_PER_TX_LIMIT
Tangui-Bitfly Nov 18, 2024
caf4ce3
Merge remote-tracking branch 'origin/master' into BEDS-536/fix-intern…
guybrush Nov 19, 2024
5b7b9d2
fix(bigtable): retry on grpc internal err
Tangui-Bitfly Nov 26, 2024
da00e8d
fix(re index): log error rather than returning error and panicking
Tangui-Bitfly Nov 27, 2024
e8e2ee0
feat(re index): re print read error at the end
Tangui-Bitfly Nov 28, 2024
3e3f64d
fix(TransformEnsNameRegistered): return none nil if ignored chainID
Tangui-Bitfly Nov 29, 2024
0db781a
fix(db2/WithFallback): fallback on syscall.ECONNRESET
Tangui-Bitfly Nov 29, 2024
d542378
fix(blockHash): prevent wrong calculated hash
Tangui-Bitfly Dec 20, 2024
f65de95
fix: return error if mismatch between receipts and transactions length
Tangui-Bitfly Jan 13, 2025
3321f74
fix: blockhash read from node response
Tangui-Bitfly Jan 16, 2025
ad85af2
Merge branch 'master' into BEDS-536/fix-internal-transfer-merge
Tangui-Bitfly Jan 22, 2025
c3f8fda
fix: merge go mod
Tangui-Bitfly Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cache/tiered_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/sirupsen/logrus"
)

var _ TieredCacher = (*tieredCache)(nil)

// Tiered cache is a cache implementation combining a
type tieredCache struct {
localGoCache *freecache.Cache
Expand All @@ -31,7 +33,19 @@ type RemoteCache interface {
GetBool(ctx context.Context, key string) (bool, error)
}

var TieredCache *tieredCache
type TieredCacher interface {
Set(key string, value interface{}, expiration time.Duration) error
SetString(key string, value string, expiration time.Duration) error
SetUint64(key string, value uint64, expiration time.Duration) error
SetBool(key string, value bool, expiration time.Duration) error

GetStringWithLocalTimeout(key string, localExpiration time.Duration) (string, error)
GetUint64WithLocalTimeout(key string, localExpiration time.Duration) (uint64, error)
GetBoolWithLocalTimeout(key string, localExpiration time.Duration) (bool, error)
GetWithLocalTimeout(key string, localExpiration time.Duration, returnValue interface{}) (interface{}, error)
}

var TieredCache TieredCacher

func MustInitTieredCache(redisAddress string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
Expand Down
36 changes: 22 additions & 14 deletions db/bigtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Bigtable struct {

tableMachineMetrics *gcp_bigtable.Table

redisCache *redis.Client
redisCache RedisClient

LastAttestationCache map[uint64]uint64
LastAttestationCacheMux *sync.Mutex
Expand All @@ -79,10 +79,30 @@ type Bigtable struct {
machineMetricsQueuedWritesChan chan (types.BulkMutation)
}

type RedisClient interface {
SCard(ctx context.Context, key string) *redis.IntCmd
SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.BoolCmd
Pipeline() redis.Pipeliner
Get(ctx context.Context, key string) *redis.StringCmd
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *redis.StatusCmd
}

func InitBigtable(project, instance, chainId, redisAddress string) (*Bigtable, error) {
rdc := redis.NewClient(&redis.Options{
Addr: redisAddress,
ReadTimeout: time.Second * 20,
})
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
if err := rdc.Ping(ctx).Err(); err != nil {
return nil, err
}

if utils.Config.Bigtable.Emulator {
return InitBigtableWithCache(ctx, project, instance, chainId, rdc)
}

func InitBigtableWithCache(ctx context.Context, project, instance, chainId string, rdc RedisClient) (*Bigtable, error) {
if utils.Config.Bigtable.Emulator {
if utils.Config.Bigtable.EmulatorHost == "" {
utils.Config.Bigtable.EmulatorHost = "127.0.0.1"
}
Expand All @@ -93,26 +113,14 @@ func InitBigtable(project, instance, chainId, redisAddress string) (*Bigtable, e
logger.Fatalf("unable to set bigtable emulator environment variable: %v", err)
}
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

poolSize := 50
btClient, err := gcp_bigtable.NewClient(ctx, project, instance, option.WithGRPCConnectionPool(poolSize))
// btClient, err := gcp_bigtable.NewClient(context.Background(), project, instance)

if err != nil {
return nil, err
}

rdc := redis.NewClient(&redis.Options{
Addr: redisAddress,
ReadTimeout: time.Second * 20,
})

if err := rdc.Ping(ctx).Err(); err != nil {
return nil, err
}

bt := &Bigtable{
client: btClient,
tableData: btClient.Open("data"),
Expand Down
25 changes: 20 additions & 5 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"log"
"math/big"
"sort"
"strconv"
"strings"
"sync"
"time"
Expand All @@ -24,8 +25,6 @@ import (
"github.com/gobitfly/eth2-beaconchain-explorer/types"
"github.com/gobitfly/eth2-beaconchain-explorer/utils"

"strconv"

gcp_bigtable "cloud.google.com/go/bigtable"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -1015,6 +1014,7 @@ func (bigtable *Bigtable) TransformTx(blk *types.Eth1Block, cache *freecache.Cac
BlobGasPrice: tx.GetBlobGasPrice(),
IsContractCreation: isContract,
ErrorMsg: tx.GetErrorMsg(),
Status: tx.Status,
}
// Mark Sender and Recipient for balance update
bigtable.markBalanceUpdate(indexedTx.From, []byte{0x0}, bulkMetadataUpdates, cache)
Expand Down Expand Up @@ -1305,6 +1305,7 @@ func (bigtable *Bigtable) TransformItx(blk *types.Eth1Block, cache *freecache.Ca
From: itx.GetFrom(),
To: itx.GetTo(),
Value: itx.GetValue(),
Reverted: itx.GetReverted(),
}

bigtable.markBalanceUpdate(indexedItx.To, []byte{0x0}, bulkMetadataUpdates, cache)
Expand Down Expand Up @@ -2346,7 +2347,7 @@ func (bigtable *Bigtable) GetAddressTransactionsTableData(address []byte, pageTo
}

tableData[i] = []interface{}{
utils.FormatTransactionHash(t.Hash, t.ErrorMsg == ""),
utils.FormatTransactionHashFromStatus(t.Hash, t.Status),
utils.FormatMethod(bigtable.GetMethodLabel(t.MethodId, contractInteraction)),
utils.FormatBlockNumber(t.BlockNumber),
utils.FormatTimestamp(t.Time.AsTime().Unix()),
Expand Down Expand Up @@ -2825,7 +2826,7 @@ func (bigtable *Bigtable) GetAddressInternalTableData(address []byte, pageToken
}

tableData[i] = []interface{}{
utils.FormatTransactionHash(t.ParentHash, true),
utils.FormatTransactionHash(t.ParentHash, !t.Reverted),
utils.FormatBlockNumber(t.BlockNumber),
utils.FormatTimestamp(t.Time.AsTime().Unix()),
utils.FormatAddressWithLimitsInAddressPageTable(address, t.From, BigtableClient.GetAddressLabel(fromName, from_contractInteraction), from_contractInteraction != types.CONTRACT_NONE, digitLimitInAddressPagesTable, nameLimitInAddressPagesTable, true),
Expand Down Expand Up @@ -2869,7 +2870,20 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
}

data := make([]types.ITransaction, 0, len(parityTrace)-1)
var revertSource []int64
for i := 1; i < len(parityTrace); i++ {
var reverted bool
if parityTrace[i].Error != "" {
reverted = true
// only save the highest root revert
if !isSubset(parityTrace[i].TraceAddress, revertSource) {
revertSource = parityTrace[i].TraceAddress
}
}
if isSubset(parityTrace[i].TraceAddress, revertSource) {
reverted = true
}

from, to, value, tx_type := parityTrace[i].ConvertFields()
if tx_type == "suicide" {
// erigon's "suicide" might be misleading for users
Expand All @@ -2896,8 +2910,9 @@ func (bigtable *Bigtable) GetInternalTransfersForTransaction(transaction []byte,
From: utils.FormatAddress(from, nil, fromName, false, from_contractInteraction != types.CONTRACT_NONE, true),
To: utils.FormatAddress(to, nil, toName, false, to_contractInteraction != types.CONTRACT_NONE, true),
Amount: utils.FormatElCurrency(value, currency, 8, true, false, false, true),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, parityTrace[i].Error == "", bigtable.GetMethodLabel(input, from_contractInteraction)),
TracePath: utils.FormatTracePath(tx_type, parityTrace[i].TraceAddress, !reverted, bigtable.GetMethodLabel(input, from_contractInteraction)),
Advanced: tx_type == "delegatecall" || string(value) == "\x00",
Reverted: reverted,
}

gaslimit, err := strconv.ParseUint(parityTrace[i].Action.Gas, 0, 0)
Expand Down
4 changes: 3 additions & 1 deletion db/bigtable_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
gcp_bigtable "cloud.google.com/go/bigtable"
)

var ErrTableAlreadyExist = fmt.Errorf("aborting bigtable schema init as tables are already present")

func InitBigtableSchema() error {

tables := make(map[string]map[string]gcp_bigtable.GCPolicy)
Expand Down Expand Up @@ -62,7 +64,7 @@ func InitBigtableSchema() error {
}

if len(existingTables) > 0 {
return fmt.Errorf("aborting bigtable schema init as tables are already present")
return ErrTableAlreadyExist
}

for name, definition := range tables {
Expand Down
13 changes: 12 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package db

import (
"bytes"
"context"
"database/sql"
"embed"
"encoding/hex"
Expand Down Expand Up @@ -37,9 +38,19 @@ var EmbedMigrations embed.FS

var DBPGX *pgxpool.Conn

type SQLReaderDb interface {
Close() error
Get(dest interface{}, query string, args ...interface{}) error
Select(dest interface{}, query string, args ...interface{}) error
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Query(query string, args ...any) (*sql.Rows, error)
Preparex(query string) (*sqlx.Stmt, error)
Rebind(query string) string
}

// DB is a pointer to the explorer-database
var WriterDb *sqlx.DB
var ReaderDb *sqlx.DB
var ReaderDb SQLReaderDb

var logger = logrus.StandardLogger().WithField("module", "db")

Expand Down
4 changes: 2 additions & 2 deletions db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
totalBlobCount = totalBlobCount.Add(decimal.NewFromInt(int64(len(tx.BlobVersionedHashes))))

default:
logger.Fatalf("error unknown tx type %v hash: %x", tx.Status, tx.Hash)
logger.Fatalf("error unknown tx type %v hash: %x", tx.Type, tx.Hash)
}
totalTxFees = totalTxFees.Add(txFees)

Expand All @@ -1646,7 +1646,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
failedTxCount += 1
totalFailedGasUsed = totalFailedGasUsed.Add(gasUsed)
totalFailedTxFee = totalFailedTxFee.Add(txFees)
case 1:
case 1, 2:
successTxCount += 1
default:
logger.Fatalf("error unknown status code %v hash: %x", tx.Status, tx.Hash)
Expand Down
16 changes: 16 additions & 0 deletions db/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package db

func isSubset[E comparable](big []E, short []E) bool {
if len(short) == 0 {
return false
}
if len(big) < len(short) {
return false
}
for i := 0; i < len(short); i++ {
if big[i] != short[i] {
return false
}
}
return true
}
Loading
Loading