Refactor to use plugeth-statediff #1

Merged
roysc merged 5 commits from refactor-for-plugin into v5 2023-09-20 06:16:57 +00:00
2 changed files with 14 additions and 12 deletions
Showing only changes of commit 040f504921 - Show all commits

View File

@ -11,7 +11,7 @@ const (
AND header_cids.block_number <= (SELECT block_number AND header_cids.block_number <= (SELECT block_number
FROM eth.header_cids FROM eth.header_cids
WHERE block_hash = $2) WHERE block_hash = $2)
AND header_cids.block_hash = (SELECT canonical_header_hash(header_cids.block_number)) AND header_cids.canonical
roysc marked this conversation as resolved
Review

Nice catch.

Nice catch.
ORDER BY header_cids.block_number DESC ORDER BY header_cids.block_number DESC
LIMIT 1` LIMIT 1`
GetStorageSlot = `SELECT val, removed, state_leaf_removed FROM get_storage_at_by_hash($1, $2, $3)` GetStorageSlot = `SELECT val, removed, state_leaf_removed FROM get_storage_at_by_hash($1, $2, $3)`

View File

@ -143,14 +143,14 @@ func TestSQLXSuite(t *testing.T) {
} }
func insertSuiteData(t *testing.T, database sql.Database) { func insertSuiteData(t *testing.T, database sql.Database) {
require.NoError(t, insertHeaderCID(database, BlockHash.String(), BlockParentHash.String(), BlockNumber.Uint64())) require.NoError(t, insertHeaderCID(database, BlockHash.String(), BlockParentHash.String(), BlockNumber.Uint64(), true))
require.NoError(t, insertHeaderCID(database, BlockHash2.String(), BlockHash.String(), BlockNumber2)) require.NoError(t, insertHeaderCID(database, BlockHash2.String(), BlockHash.String(), BlockNumber2, true))
require.NoError(t, insertHeaderCID(database, BlockHash3.String(), BlockHash2.String(), BlockNumber3)) require.NoError(t, insertHeaderCID(database, BlockHash3.String(), BlockHash2.String(), BlockNumber3, true))
require.NoError(t, insertHeaderCID(database, BlockHash4.String(), BlockHash3.String(), BlockNumber4)) require.NoError(t, insertHeaderCID(database, BlockHash4.String(), BlockHash3.String(), BlockNumber4, true))
require.NoError(t, insertHeaderCID(database, NonCanonicalHash4.String(), BlockHash3.String(), BlockNumber4)) require.NoError(t, insertHeaderCID(database, NonCanonicalHash4.String(), BlockHash3.String(), BlockNumber4, false))
require.NoError(t, insertHeaderCID(database, BlockHash5.String(), BlockHash4.String(), BlockNumber5)) require.NoError(t, insertHeaderCID(database, BlockHash5.String(), BlockHash4.String(), BlockNumber5, true))
require.NoError(t, insertHeaderCID(database, NonCanonicalHash5.String(), NonCanonicalHash4.String(), BlockNumber5)) require.NoError(t, insertHeaderCID(database, NonCanonicalHash5.String(), NonCanonicalHash4.String(), BlockNumber5, false))
require.NoError(t, insertHeaderCID(database, BlockHash6.String(), BlockHash5.String(), BlockNumber6)) require.NoError(t, insertHeaderCID(database, BlockHash6.String(), BlockHash5.String(), BlockNumber6, true))
require.NoError(t, insertStateCID(database, stateModel{ require.NoError(t, insertStateCID(database, stateModel{
BlockNumber: BlockNumber.Uint64(), BlockNumber: BlockNumber.Uint64(),
BlockHash: BlockHash.String(), BlockHash: BlockHash.String(),
@ -337,7 +337,7 @@ func testSuite(t *testing.T, db state.StateDatabase) {
}) })
} }
func insertHeaderCID(db sql.Database, blockHash, parentHash string, blockNumber uint64) error { func insertHeaderCID(db sql.Database, blockHash, parentHash string, blockNumber uint64, canon bool) error {
cid, err := util.Keccak256ToCid(ipld.MEthHeader, common.HexToHash(blockHash).Bytes()) cid, err := util.Keccak256ToCid(ipld.MEthHeader, common.HexToHash(blockHash).Bytes())
if err != nil { if err != nil {
return err return err
@ -356,8 +356,9 @@ func insertHeaderCID(db sql.Database, blockHash, parentHash string, blockNumber
uncles_hash, uncles_hash,
bloom, bloom,
timestamp, timestamp,
coinbase coinbase,
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)` canonical
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)`
_, err = db.Exec(testCtx, sql, _, err = db.Exec(testCtx, sql,
blockNumber, blockNumber,
blockHash, blockHash,
@ -371,6 +372,7 @@ func insertHeaderCID(db sql.Database, blockHash, parentHash string, blockNumber
[]byte{}, []byte{},
Header.Time, Header.Time,
Header.Coinbase.String(), Header.Coinbase.String(),
canon,
) )
return err return err
} }