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

analyzer/block: Hardcode pre-Eden stale accounts #654

Merged
merged 8 commits into from
Mar 12, 2024
1 change: 1 addition & 0 deletions analyzer/block/block.go
Original file line number Diff line number Diff line change
@@ -235,6 +235,7 @@ func (b *blockBasedAnalyzer) softEnqueueGapsInProcessedBlocks(ctx context.Contex
// - If the most recently processed block was not processed by slow-sync (i.e. by fast sync, or not
// at all), triggers a finalization of the fast-sync process.
func (b *blockBasedAnalyzer) ensureSlowSyncPrerequisites(ctx context.Context) (ok bool) {
b.logger.Info("slow sync: checking prerequisites: checking that blocks processed so far form a contiguous range")
isContiguous, maxProcessedHeight, err := b.processedSubrangeInfo(ctx)
if err != nil {
b.logger.Error("Failed to obtain info about already-processed blocks", "err", err)
33 changes: 19 additions & 14 deletions analyzer/evmtokenbalances/evm_token_balances.go
Original file line number Diff line number Diff line change
@@ -112,17 +112,19 @@ func NewAnalyzer(
}

type StaleTokenBalance struct {
TokenAddr string
AccountAddr string
Type common.TokenType
Balance *big.Int
TokenAddrContextIdentifier string
TokenAddrContextVersion int
TokenAddrData []byte
AccountAddrContextIdentifier string
AccountAddrContextVersion int
TokenAddr string
AccountAddr string
Type common.TokenType
Balance *big.Int
TokenAddrContextIdentifier string
TokenAddrContextVersion int
TokenAddrData []byte
DownloadRound uint64

// Not necessary for native tokens.
AccountAddrContextIdentifier *string
AccountAddrContextVersion *int
AccountAddrData []byte
DownloadRound uint64
}

func (p *processor) GetItems(ctx context.Context, limit uint64) ([]*StaleTokenBalance, error) {
@@ -160,10 +162,6 @@ func (p *processor) GetItems(ctx context.Context, limit uint64) ([]*StaleTokenBa
}

func (p *processor) ProcessItem(ctx context.Context, batch *storage.QueryBatch, staleTokenBalance *StaleTokenBalance) error {
accountEthAddr, err := client.EVMEthAddrFromPreimage(staleTokenBalance.AccountAddrContextIdentifier, staleTokenBalance.AccountAddrContextVersion, staleTokenBalance.AccountAddrData)
if err != nil {
return fmt.Errorf("account address: %w", err)
}
switch staleTokenBalance.Type {
case common.TokenTypeUnsupported:
// Do nothing; we'll just mark this token as processed so we remove it from the queue.
@@ -204,6 +202,13 @@ func (p *processor) ProcessItem(ctx context.Context, batch *storage.QueryBatch,
if err != nil {
return fmt.Errorf("token address: %w", err)
}
if staleTokenBalance.AccountAddrContextIdentifier == nil || staleTokenBalance.AccountAddrContextVersion == nil || staleTokenBalance.AccountAddrData == nil {
return fmt.Errorf("account address: missing preimage for: '%s' (token address: '%s')", staleTokenBalance.AccountAddr, staleTokenBalance.TokenAddr)
}
accountEthAddr, err := client.EVMEthAddrFromPreimage(*staleTokenBalance.AccountAddrContextIdentifier, *staleTokenBalance.AccountAddrContextVersion, staleTokenBalance.AccountAddrData)
if err != nil {
return fmt.Errorf("account address: %w", err)
}
balanceData, err := evm.EVMDownloadTokenBalance(
ctx,
p.logger,
8 changes: 4 additions & 4 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
@@ -634,7 +634,7 @@ var (
($1, $2, $3, $4)
ON CONFLICT (runtime, token_address, account_address) DO UPDATE
SET
last_mutate_round = excluded.last_mutate_round`
last_mutate_round = GREATEST(excluded.last_mutate_round, analysis.evm_token_balances.last_mutate_round)`

RuntimeFastSyncEVMTokenBalanceAnalysisMutateRoundInsert = `
INSERT INTO todo_updates.evm_token_balances
@@ -947,7 +947,7 @@ var (

RuntimeEvmVerifiedContractTxs = `
WITH abi_contracts AS (
SELECT
SELECT
runtime,
contract_address AS addr,
abi,
@@ -956,13 +956,13 @@ var (
WHERE
runtime = $1 AND abi IS NOT NULL
)
SELECT
SELECT
abi_contracts.addr,
abi_contracts.abi,
txs.tx_hash,
decode(txs.body->>'data', 'base64'),
txs.error_message_raw
FROM abi_contracts
FROM abi_contracts
JOIN chain.runtime_transactions as txs ON
txs.runtime = abi_contracts.runtime AND
txs.to = abi_contracts.addr AND
9 changes: 9 additions & 0 deletions analyzer/runtime/runtime.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
"github.com/oasisprotocol/nexus/analyzer/block"
"github.com/oasisprotocol/nexus/analyzer/queries"
evm "github.com/oasisprotocol/nexus/analyzer/runtime/evm"
"github.com/oasisprotocol/nexus/analyzer/runtime/static"
uncategorized "github.com/oasisprotocol/nexus/analyzer/uncategorized"
apiTypes "github.com/oasisprotocol/nexus/api/v1/types"
"github.com/oasisprotocol/nexus/common"
@@ -25,6 +26,7 @@ import (

// processor is the block processor for runtimes.
type processor struct {
chain common.ChainName
runtime common.Runtime
runtimeMetadata *sdkConfig.ParaTime
mode analyzer.BlockAnalysisMode
@@ -38,6 +40,7 @@ var _ block.BlockProcessor = (*processor)(nil)

// NewRuntimeAnalyzer returns a new runtime analyzer for a runtime.
func NewRuntimeAnalyzer(
chain common.ChainName,
runtime common.Runtime,
runtimeMetadata *sdkConfig.ParaTime,
blockRange config.BlockRange,
@@ -49,6 +52,7 @@ func NewRuntimeAnalyzer(
) (analyzer.Analyzer, error) {
// Initialize runtime block processor.
processor := &processor{
chain: chain,
runtime: runtime,
runtimeMetadata: runtimeMetadata,
mode: mode,
@@ -217,6 +221,11 @@ func (m *processor) ProcessBlock(ctx context.Context, round uint64) error {
m.mode == analyzer.FastSyncMode,
)

// Perform one-off fixes: Refetch native balances that are known to be stale at a fixed height.
if err := static.QueueEVMKnownStaleAccounts(batch, m.chain, m.runtime, round, m.logger); err != nil {
return fmt.Errorf("queue eden accounts: %w", err)
}

opName := fmt.Sprintf("process_block_%s", m.runtime)
timer := m.metrics.DatabaseLatencies(m.target.Name(), opName)
defer timer.ObserveDuration()
1 change: 1 addition & 0 deletions analyzer/runtime/runtime_test.go
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ func setupAnalyzer(t *testing.T, testDb *postgres.Client, node *mockNode) analyz
}

analyzer, err := runtime.NewRuntimeAnalyzer(
"testnet",
"pontusx", // We borrow a real runtime's name to comply with DB's enums.
runtimeMetadata,
config.BlockRange{From: uint64(minRound), To: uint64(maxRound)},
Loading