fix:fix main use history network

Signed-off-by: Chen Kai <281165273grape@gmail.com>
This commit is contained in:
Chen Kai 2024-02-26 13:47:34 +08:00
parent 3c5dbf1fd8
commit f1802d610c
2 changed files with 15 additions and 5 deletions

View file

@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/portalnetwork/history"
"github.com/ethereum/go-ethereum/portalnetwork/storage/sqlite"
"github.com/ethereum/go-ethereum/rpc"
)
@ -74,7 +75,13 @@ func main() {
panic(err)
}
err = protocol.Start()
accumulator, err := history.NewMasterAccumulator()
if err != nil {
panic(err)
}
historyNetwork := history.NewHistoryNetwork(protocol, &accumulator)
err = historyNetwork.Start()
if err != nil {
panic(err)
}

View file

@ -58,7 +58,7 @@ func (e *epoch) add(header types.Header) error {
}
sszBytes, err := record.MarshalSSZ()
if err != nil {
return nil
return err
}
e.records = append(e.records, sszBytes)
return nil
@ -97,7 +97,10 @@ func (a *Accumulator) Update(header types.Header) error {
a.historicalEpochs = append(a.historicalEpochs, MixInLength(root, epochSize))
a.currentEpoch = newEpoch()
}
a.currentEpoch.add(header)
err := a.currentEpoch.add(header)
if err != nil {
return err
}
return nil
}
@ -149,7 +152,7 @@ func BuildProof(header types.Header, epochAccumulator EpochAccumulator) (Accumul
sizeBytes := make([]byte, 32)
binary.LittleEndian.PutUint32(sizeBytes, epochSize)
hashes = append(hashes, sizeBytes)
return AccumulatorProof(hashes), err
return hashes, err
}
func BuildHeaderWithProof(header types.Header, epochAccumulator EpochAccumulator) (*BlockHeaderWithProof, error) {
@ -215,7 +218,7 @@ func MixInLength(root [32]byte, length uint64) []byte {
hash := ssz.NewHasher()
hash.AppendBytes32(root[:])
hash.MerkleizeWithMixin(0, length, 0)
// length of root is 32, so we can ignore the err
// length of root is 32, so we can ignore the error
newRoot, _ := hash.HashRoot()
return newRoot[:]
}