Update to geth 1.11.5-statediff-v5 #238

Merged
telackey merged 40 commits from roy/v5-dev into v5 2023-06-01 13:53:57 +00:00
4 changed files with 28 additions and 59 deletions
Showing only changes of commit df8bec1ad0 - Show all commits

View File

@ -374,21 +374,11 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
return nil, err return nil, err
} }
// When num. of uncles = 2, // We should not have any non-determinism in the ordering of the uncles returned to us now
// Check if calculated uncle hash matches the one in header uncleHash := types.CalcUncleHash(uncles)
// If not, re-order the two uncles // Check if uncle hash matches expected hash
// Assumption: Max num. of uncles in mainnet = 2 if uncleHash != header.UncleHash {
if len(uncles) == 2 { log.Error("uncle hash mismatch for block hash: ", hash.Hex())
uncleHash := types.CalcUncleHash(uncles)
if uncleHash != header.UncleHash {
uncles[0], uncles[1] = uncles[1], uncles[0]
uncleHash = types.CalcUncleHash(uncles)
// Check if uncle hash matches after re-ordering
if uncleHash != header.UncleHash {
log.Error("uncle hash mismatch for block hash: ", hash.Hex())
}
}
} }
// Fetch transactions // Fetch transactions
@ -427,15 +417,9 @@ func (b *Backend) GetUnclesByBlockHash(tx *sqlx.Tx, hash common.Hash) ([]*types.
return nil, err return nil, err
} }
uncles := make([]*types.Header, len(uncleBytes)) uncles := make([]*types.Header, 0)
for i, bytes := range uncleBytes { if err := rlp.DecodeBytes(uncleBytes, uncles); err != nil {
var uncle types.Header return nil, err
err = rlp.DecodeBytes(bytes, &uncle)
if err != nil {
return nil, err
}
uncles[i] = &uncle
} }
return uncles, nil return uncles, nil
@ -448,15 +432,9 @@ func (b *Backend) GetUnclesByBlockHashAndNumber(tx *sqlx.Tx, hash common.Hash, n
return nil, err return nil, err
} }
uncles := make([]*types.Header, len(uncleBytes)) uncles := make([]*types.Header, 0)
for i, bytes := range uncleBytes { if err := rlp.DecodeBytes(uncleBytes, uncles); err != nil {
var uncle types.Header return nil, err
err = rlp.DecodeBytes(bytes, &uncle)
if err != nil {
return nil, err
}
uncles[i] = &uncle
} }
return uncles, nil return uncles, nil

View File

@ -365,34 +365,22 @@ func (r *Retriever) RetrieveHeaderByHash(tx *sqlx.Tx, hash common.Hash) (string,
return headerResult.CID, headerResult.Data, tx.Get(headerResult, RetrieveHeaderByHashPgStr, hash.Hex()) return headerResult.CID, headerResult.Data, tx.Get(headerResult, RetrieveHeaderByHashPgStr, hash.Hex())
} }
// RetrieveUncles returns the cids and rlp bytes for the uncles corresponding to the provided block hash, number (of non-omner root block) // RetrieveUncles returns the cid and rlp bytes for the uncle list corresponding to the provided block hash, number (of non-omner root block)
func (r *Retriever) RetrieveUncles(tx *sqlx.Tx, hash common.Hash, number uint64) ([]string, [][]byte, error) { func (r *Retriever) RetrieveUncles(tx *sqlx.Tx, hash common.Hash, number uint64) (string, []byte, error) {
uncleResults := make([]ipldResult, 0) uncleResult := new(ipldResult)
if err := tx.Select(&uncleResults, RetrieveUnclesPgStr, hash.Hex(), number); err != nil { if err := tx.Select(uncleResult, RetrieveUnclesPgStr, hash.Hex(), number); err != nil {
return nil, nil, err return "", nil, err
} }
cids := make([]string, len(uncleResults)) return uncleResult.CID, uncleResult.Data, nil
uncles := make([][]byte, len(uncleResults))
for i, res := range uncleResults {
cids[i] = res.CID
uncles[i] = res.Data
}
return cids, uncles, nil
} }
// RetrieveUnclesByBlockHash returns the cids and rlp bytes for the uncles corresponding to the provided block hash (of non-omner root block) // RetrieveUnclesByBlockHash returns the cid and rlp bytes for the uncle list corresponding to the provided block hash (of non-omner root block)
func (r *Retriever) RetrieveUnclesByBlockHash(tx *sqlx.Tx, hash common.Hash) ([]string, [][]byte, error) { func (r *Retriever) RetrieveUnclesByBlockHash(tx *sqlx.Tx, hash common.Hash) (string, []byte, error) {
uncleResults := make([]ipldResult, 0) uncleResult := new(ipldResult)
if err := tx.Select(&uncleResults, RetrieveUnclesByBlockHashPgStr, hash.Hex()); err != nil { if err := tx.Select(uncleResult, RetrieveUnclesByBlockHashPgStr, hash.Hex()); err != nil {
return nil, nil, err return "", nil, err
} }
cids := make([]string, len(uncleResults)) return uncleResult.CID, uncleResult.Data, nil
uncles := make([][]byte, len(uncleResults))
for i, res := range uncleResults {
cids[i] = res.CID
uncles[i] = res.Data
}
return cids, uncles, nil
} }
// RetrieveTransactions returns the cids and rlp bytes for the transactions corresponding to the provided block hash, number // RetrieveTransactions returns the cids and rlp bytes for the transactions corresponding to the provided block hash, number

View File

@ -20,7 +20,8 @@ const (
) )
WHERE header_cids.block_hash = $1 WHERE header_cids.block_hash = $1
AND header_cids.block_number = $2 AND header_cids.block_number = $2
ORDER BY uncle_cids.parent_hash` ORDER BY uncle_cids.parent_hash
LIMIT 1`
RetrieveUnclesByBlockHashPgStr = `SELECT uncle_cids.cid, data RetrieveUnclesByBlockHashPgStr = `SELECT uncle_cids.cid, data
FROM eth.uncle_cids FROM eth.uncle_cids
INNER JOIN eth.header_cids ON ( INNER JOIN eth.header_cids ON (
@ -32,7 +33,8 @@ const (
AND uncle_cids.block_number = blocks.block_number AND uncle_cids.block_number = blocks.block_number
) )
WHERE header_cids.block_hash = $1 WHERE header_cids.block_hash = $1
ORDER BY uncle_cids.parent_hash` ORDER BY uncle_cids.parent_hash
LIMIT 1`
RetrieveTransactionsPgStr = `SELECT transaction_cids.cid, data RetrieveTransactionsPgStr = `SELECT transaction_cids.cid, data
FROM eth.transaction_cids FROM eth.transaction_cids
INNER JOIN eth.header_cids ON ( INNER JOIN eth.header_cids ON (

View File

@ -36,6 +36,7 @@ import (
"github.com/cerc-io/ipld-eth-server/v4/pkg/eth" "github.com/cerc-io/ipld-eth-server/v4/pkg/eth"
"github.com/cerc-io/ipld-eth-server/v4/pkg/shared" "github.com/cerc-io/ipld-eth-server/v4/pkg/shared"
ipld_eth_statedb "github.com/cerc-io/ipld-eth-statedb"
) )
var ( var (