eth/catalyst: make getPayloadBodiesByRange take hex inputs (#26624)
Co-authored-by: Martin Holst Swende <martin@swende.se> Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
This commit is contained in:
parent
9842301376
commit
0c9eb8c9a4
@ -772,18 +772,18 @@ func (api *ConsensusAPI) GetPayloadBodiesByHashV1(hashes []common.Hash) []*engin
|
|||||||
|
|
||||||
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
|
// GetPayloadBodiesByRangeV1 implements engine_getPayloadBodiesByRangeV1 which allows for retrieval of a range
|
||||||
// of block bodies by the engine api.
|
// of block bodies by the engine api.
|
||||||
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
|
func (api *ConsensusAPI) GetPayloadBodiesByRangeV1(start, count hexutil.Uint64) ([]*engine.ExecutionPayloadBodyV1, error) {
|
||||||
if start == 0 || count == 0 || count > 1024 {
|
if start == 0 || count == 0 || count > 1024 {
|
||||||
return nil, engine.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
|
return nil, engine.InvalidParams.With(fmt.Errorf("invalid start or count, start: %v count: %v", start, count))
|
||||||
}
|
}
|
||||||
// limit count up until current
|
// limit count up until current
|
||||||
current := api.eth.BlockChain().CurrentBlock().NumberU64()
|
current := api.eth.BlockChain().CurrentBlock().NumberU64()
|
||||||
end := start + count
|
last := uint64(start) + uint64(count) - 1
|
||||||
if end > current {
|
if last > current {
|
||||||
end = current
|
last = current
|
||||||
}
|
}
|
||||||
var bodies []*engine.ExecutionPayloadBodyV1
|
bodies := make([]*engine.ExecutionPayloadBodyV1, 0, uint64(count))
|
||||||
for i := start; i < end; i++ {
|
for i := uint64(start); i <= last; i++ {
|
||||||
block := api.eth.BlockChain().GetBlockByNumber(i)
|
block := api.eth.BlockChain().GetBlockByNumber(i)
|
||||||
bodies = append(bodies, getBody(block))
|
bodies = append(bodies, getBody(block))
|
||||||
}
|
}
|
||||||
|
@ -1311,9 +1311,14 @@ func TestGetBlockBodiesByRange(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
results []*types.Body
|
results []*types.Body
|
||||||
start uint64
|
start hexutil.Uint64
|
||||||
count uint64
|
count hexutil.Uint64
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
results: []*types.Body{blocks[9].Body()},
|
||||||
|
start: 10,
|
||||||
|
count: 1,
|
||||||
|
},
|
||||||
// Genesis
|
// Genesis
|
||||||
{
|
{
|
||||||
results: []*types.Body{blocks[0].Body()},
|
results: []*types.Body{blocks[0].Body()},
|
||||||
@ -1334,14 +1339,25 @@ func TestGetBlockBodiesByRange(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// unavailable block
|
// unavailable block
|
||||||
{
|
{
|
||||||
results: []*types.Body{blocks[18].Body()},
|
results: []*types.Body{blocks[18].Body(), blocks[19].Body()},
|
||||||
start: 19,
|
start: 19,
|
||||||
count: 3,
|
count: 3,
|
||||||
},
|
},
|
||||||
// after range
|
// unavailable block
|
||||||
|
{
|
||||||
|
results: []*types.Body{blocks[19].Body()},
|
||||||
|
start: 20,
|
||||||
|
count: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
results: []*types.Body{blocks[19].Body()},
|
||||||
|
start: 20,
|
||||||
|
count: 1,
|
||||||
|
},
|
||||||
|
// whole range unavailable
|
||||||
{
|
{
|
||||||
results: make([]*types.Body, 0),
|
results: make([]*types.Body, 0),
|
||||||
start: 20,
|
start: 22,
|
||||||
count: 2,
|
count: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -1354,11 +1370,11 @@ func TestGetBlockBodiesByRange(t *testing.T) {
|
|||||||
if len(result) == len(test.results) {
|
if len(result) == len(test.results) {
|
||||||
for i, r := range result {
|
for i, r := range result {
|
||||||
if !equalBody(test.results[i], r) {
|
if !equalBody(test.results[i], r) {
|
||||||
t.Fatalf("test %v: invalid response: expected %+v got %+v", k, test.results[i], r)
|
t.Fatalf("test %d: invalid response: expected \n%+v\ngot\n%+v", k, test.results[i], r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Fatalf("invalid length want %v got %v", len(test.results), len(result))
|
t.Fatalf("test %d: invalid length want %v got %v", k, len(test.results), len(result))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1369,8 +1385,8 @@ func TestGetBlockBodiesByRangeInvalidParams(t *testing.T) {
|
|||||||
defer node.Close()
|
defer node.Close()
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
start uint64
|
start hexutil.Uint64
|
||||||
count uint64
|
count hexutil.Uint64
|
||||||
}{
|
}{
|
||||||
// Genesis
|
// Genesis
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user