adapt uncle retrieval methods to work for v5
This commit is contained in:
parent
aab5a2ef0b
commit
df8bec1ad0
@ -374,22 +374,12 @@ func (b *Backend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Blo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// When num. of uncles = 2,
|
||||
// Check if calculated uncle hash matches the one in header
|
||||
// If not, re-order the two uncles
|
||||
// Assumption: Max num. of uncles in mainnet = 2
|
||||
if len(uncles) == 2 {
|
||||
// We should not have any non-determinism in the ordering of the uncles returned to us now
|
||||
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
|
||||
// Check if uncle hash matches expected hash
|
||||
if uncleHash != header.UncleHash {
|
||||
log.Error("uncle hash mismatch for block hash: ", hash.Hex())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch transactions
|
||||
transactions, err := b.GetTransactionsByBlockHashAndNumber(tx, hash, blockNumber)
|
||||
@ -427,17 +417,11 @@ func (b *Backend) GetUnclesByBlockHash(tx *sqlx.Tx, hash common.Hash) ([]*types.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uncles := make([]*types.Header, len(uncleBytes))
|
||||
for i, bytes := range uncleBytes {
|
||||
var uncle types.Header
|
||||
err = rlp.DecodeBytes(bytes, &uncle)
|
||||
if err != nil {
|
||||
uncles := make([]*types.Header, 0)
|
||||
if err := rlp.DecodeBytes(uncleBytes, uncles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uncles[i] = &uncle
|
||||
}
|
||||
|
||||
return uncles, nil
|
||||
}
|
||||
|
||||
@ -448,17 +432,11 @@ func (b *Backend) GetUnclesByBlockHashAndNumber(tx *sqlx.Tx, hash common.Hash, n
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uncles := make([]*types.Header, len(uncleBytes))
|
||||
for i, bytes := range uncleBytes {
|
||||
var uncle types.Header
|
||||
err = rlp.DecodeBytes(bytes, &uncle)
|
||||
if err != nil {
|
||||
uncles := make([]*types.Header, 0)
|
||||
if err := rlp.DecodeBytes(uncleBytes, uncles); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
uncles[i] = &uncle
|
||||
}
|
||||
|
||||
return uncles, nil
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
|
||||
// RetrieveUncles returns the cids and rlp bytes for the uncles 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) {
|
||||
uncleResults := make([]ipldResult, 0)
|
||||
if err := tx.Select(&uncleResults, RetrieveUnclesPgStr, hash.Hex(), number); err != nil {
|
||||
return nil, nil, err
|
||||
// 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) {
|
||||
uncleResult := new(ipldResult)
|
||||
if err := tx.Select(uncleResult, RetrieveUnclesPgStr, hash.Hex(), number); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
cids := make([]string, len(uncleResults))
|
||||
uncles := make([][]byte, len(uncleResults))
|
||||
for i, res := range uncleResults {
|
||||
cids[i] = res.CID
|
||||
uncles[i] = res.Data
|
||||
}
|
||||
return cids, uncles, nil
|
||||
return uncleResult.CID, uncleResult.Data, nil
|
||||
}
|
||||
|
||||
// RetrieveUnclesByBlockHash returns the cids and rlp bytes for the uncles corresponding to the provided block hash (of non-omner root block)
|
||||
func (r *Retriever) RetrieveUnclesByBlockHash(tx *sqlx.Tx, hash common.Hash) ([]string, [][]byte, error) {
|
||||
uncleResults := make([]ipldResult, 0)
|
||||
if err := tx.Select(&uncleResults, RetrieveUnclesByBlockHashPgStr, hash.Hex()); err != nil {
|
||||
return nil, nil, err
|
||||
// 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) {
|
||||
uncleResult := new(ipldResult)
|
||||
if err := tx.Select(uncleResult, RetrieveUnclesByBlockHashPgStr, hash.Hex()); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
cids := make([]string, len(uncleResults))
|
||||
uncles := make([][]byte, len(uncleResults))
|
||||
for i, res := range uncleResults {
|
||||
cids[i] = res.CID
|
||||
uncles[i] = res.Data
|
||||
}
|
||||
return cids, uncles, nil
|
||||
return uncleResult.CID, uncleResult.Data, nil
|
||||
}
|
||||
|
||||
// RetrieveTransactions returns the cids and rlp bytes for the transactions corresponding to the provided block hash, number
|
||||
|
@ -20,7 +20,8 @@ const (
|
||||
)
|
||||
WHERE header_cids.block_hash = $1
|
||||
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
|
||||
FROM eth.uncle_cids
|
||||
INNER JOIN eth.header_cids ON (
|
||||
@ -32,7 +33,8 @@ const (
|
||||
AND uncle_cids.block_number = blocks.block_number
|
||||
)
|
||||
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
|
||||
FROM eth.transaction_cids
|
||||
INNER JOIN eth.header_cids ON (
|
||||
|
@ -36,6 +36,7 @@ import (
|
||||
|
||||
"github.com/cerc-io/ipld-eth-server/v4/pkg/eth"
|
||||
"github.com/cerc-io/ipld-eth-server/v4/pkg/shared"
|
||||
ipld_eth_statedb "github.com/cerc-io/ipld-eth-statedb"
|
||||
)
|
||||
|
||||
var (
|
||||
|
Loading…
Reference in New Issue
Block a user