mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 06:53:46 +00:00
fix: PortalReceipts ssz error in history network
This commit is contained in:
parent
777aad61ed
commit
06f2d232d2
4 changed files with 76 additions and 16 deletions
|
|
@ -125,11 +125,19 @@ func TestValidateHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReceiptsAndBody(t *testing.T) {
|
func TestReceiptsAndBody(t *testing.T) {
|
||||||
entryMap, err := parseDataForBlock14764013()
|
entryMap, err := parseDataForBlock("block_14764013.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
testReceiptsAndBody(entryMap, t)
|
||||||
|
|
||||||
|
entryMap, err = parseDataForBlock("block_8951059.json")
|
||||||
|
require.NoError(t, err)
|
||||||
|
testReceiptsAndBody(entryMap, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testReceiptsAndBody(entryMap map[string]contentEntry, t *testing.T) {
|
||||||
historyNetwork, err := genHistoryNetwork(":7893", nil)
|
historyNetwork, err := genHistoryNetwork(":7893", nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
defer historyNetwork.Stop()
|
||||||
|
|
||||||
headerEntry := entryMap["header"]
|
headerEntry := entryMap["header"]
|
||||||
// validateContents will store the content
|
// validateContents will store the content
|
||||||
|
|
@ -194,7 +202,7 @@ func TestGetContentByKey(t *testing.T) {
|
||||||
// wait node start
|
// wait node start
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
entryMap, err := parseDataForBlock14764013()
|
entryMap, err := parseDataForBlock("block_14764013.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
headerEntry := entryMap["header"]
|
headerEntry := entryMap["header"]
|
||||||
|
|
@ -450,7 +458,7 @@ func genHistoryNetwork(addr string, bootNodes []*enode.Node) (*HistoryNetwork, e
|
||||||
return NewHistoryNetwork(portalProtocol, &accu), nil
|
return NewHistoryNetwork(portalProtocol, &accu), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseDataForBlock14764013() (map[string]contentEntry, error) {
|
func parseDataForBlock(fileName string) (map[string]contentEntry, error) {
|
||||||
content, err := os.ReadFile("./testdata/block_14764013.json")
|
content, err := os.ReadFile("./testdata/block_14764013.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
16
portalnetwork/history/testdata/block_8951059.json
vendored
Normal file
16
portalnetwork/history/testdata/block_8951059.json
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -108,7 +108,7 @@ func (p *BlockHeaderProof) HashTreeRootWith(_ ssz.HashWalker) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PortalReceipts struct {
|
type PortalReceipts struct {
|
||||||
Receipts [][]byte `ssz-max:"134217728,16384"`
|
Receipts [][]byte `ssz-max:"16384,134217728"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalSSZ ssz marshals the PortalReceipts object
|
// MarshalSSZ ssz marshals the PortalReceipts object
|
||||||
|
|
@ -119,9 +119,9 @@ func (p *PortalReceipts) MarshalSSZ() ([]byte, error) {
|
||||||
// MarshalSSZTo ssz marshals the PortalReceipts object to a target array
|
// MarshalSSZTo ssz marshals the PortalReceipts object to a target array
|
||||||
func (p *PortalReceipts) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
func (p *PortalReceipts) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||||
dst = buf
|
dst = buf
|
||||||
|
// Field (0) 'Receipts'
|
||||||
if size := len(p.Receipts); size > 134217728 {
|
if size := len(p.Receipts); size > 16384 {
|
||||||
err = ssz.ErrListTooBigFn("PortalReceipts.Receipts", size, 134217728)
|
err = ssz.ErrListTooBigFn("PortalReceipts.Receipts", size, 16384)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
@ -132,8 +132,8 @@ func (p *PortalReceipts) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ii := 0; ii < len(p.Receipts); ii++ {
|
for ii := 0; ii < len(p.Receipts); ii++ {
|
||||||
if size := len(p.Receipts[ii]); size > 16384 {
|
if size := len(p.Receipts[ii]); size > 134217728 {
|
||||||
err = ssz.ErrBytesLengthFn("PortalReceipts.Receipts[ii]", size, 16384)
|
err = ssz.ErrBytesLengthFn("PortalReceipts.Receipts[ii]", size, 134217728)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dst = append(dst, p.Receipts[ii]...)
|
dst = append(dst, p.Receipts[ii]...)
|
||||||
|
|
@ -142,7 +142,7 @@ func (p *PortalReceipts) MarshalSSZTo(buf []byte) (dst []byte, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalSSZ ssz unmarshal the PortalReceipts object
|
// UnmarshalSSZ ssz unmarshals the PortalReceipts object
|
||||||
func (p *PortalReceipts) UnmarshalSSZ(buf []byte) error {
|
func (p *PortalReceipts) UnmarshalSSZ(buf []byte) error {
|
||||||
var err error
|
var err error
|
||||||
size := uint64(len(buf))
|
size := uint64(len(buf))
|
||||||
|
|
@ -151,13 +151,13 @@ func (p *PortalReceipts) UnmarshalSSZ(buf []byte) error {
|
||||||
}
|
}
|
||||||
// Field (0) 'Receipts'
|
// Field (0) 'Receipts'
|
||||||
{
|
{
|
||||||
num, err := ssz.DecodeDynamicLength(buf, 134217728)
|
num, err := ssz.DecodeDynamicLength(buf, 16384)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.Receipts = make([][]byte, num)
|
p.Receipts = make([][]byte, num)
|
||||||
err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) {
|
err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) {
|
||||||
if len(buf) > 16384 {
|
if len(buf) > 134217728 {
|
||||||
return ssz.ErrBytesLength
|
return ssz.ErrBytesLength
|
||||||
}
|
}
|
||||||
if cap(p.Receipts[indx]) == 0 {
|
if cap(p.Receipts[indx]) == 0 {
|
||||||
|
|
@ -186,7 +186,43 @@ func (p *PortalReceipts) SizeSSZ() (size int) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashTreeRootWith ssz hashes the PortalReceipts object with a hasher
|
// HashTreeRoot ssz hashes the PortalReceipts object
|
||||||
func (p *PortalReceipts) HashTreeRootWith(_ ssz.HashWalker) (err error) {
|
func (p *PortalReceipts) HashTreeRoot() ([32]byte, error) {
|
||||||
panic("implement me")
|
return ssz.HashWithDefaultHasher(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HashTreeRootWith ssz hashes the PortalReceipts object with a hasher
|
||||||
|
func (p *PortalReceipts) HashTreeRootWith(hh ssz.HashWalker) (err error) {
|
||||||
|
indx := hh.Index()
|
||||||
|
|
||||||
|
// Field (0) 'Receipts'
|
||||||
|
{
|
||||||
|
subIndx := hh.Index()
|
||||||
|
num := uint64(len(p.Receipts))
|
||||||
|
if num > 16384 {
|
||||||
|
err = ssz.ErrIncorrectListSize
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, elem := range p.Receipts {
|
||||||
|
{
|
||||||
|
elemIndx := hh.Index()
|
||||||
|
byteLen := uint64(len(elem))
|
||||||
|
if byteLen > 134217728 {
|
||||||
|
err = ssz.ErrIncorrectListSize
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hh.AppendBytes32(elem)
|
||||||
|
hh.MerkleizeWithMixin(elemIndx, byteLen, (134217728+31)/32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hh.MerkleizeWithMixin(subIndx, num, 16384)
|
||||||
|
}
|
||||||
|
|
||||||
|
hh.Merkleize(indx)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTree ssz hashes the PortalReceipts object
|
||||||
|
func (p *PortalReceipts) GetTree() (*ssz.Node, error) {
|
||||||
|
return ssz.ProofTree(p)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// Code generated by fastssz. DO NOT EDIT.
|
// Code generated by fastssz. DO NOT EDIT.
|
||||||
// Hash: e363d89d6737d1848b24978171e257d960f85a212d73a7dddcfa56d76800f527
|
// Hash: 61b113382a0931d2f239bb8712b2c09846d541b565494645b8d12d572b8b3dfb
|
||||||
// Version: 0.1.3
|
// Version: 0.1.3
|
||||||
package history
|
package history
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue