replace with hash tree root

This commit is contained in:
nisdas
2019-07-12 17:38:37 +05:30
parent a5d483aa50
commit 77d8f16a16
36 changed files with 179 additions and 230 deletions

View File

@@ -31,11 +31,11 @@ go_test(
deps = [
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],

View File

@@ -8,9 +8,9 @@ import (
"testing"
"github.com/prysmaticlabs/go-bitfield"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
@@ -178,7 +178,7 @@ func TestLatestAttestationTarget_ReturnsLatestAttestedBlock(t *testing.T) {
if err := beaconDB.SaveBlock(block); err != nil {
t.Fatalf("could not save block: %v", err)
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
log.Fatalf("could not hash block: %v", err)
}

View File

@@ -20,7 +20,6 @@ go_library(
"//beacon-chain/operations:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
@@ -55,7 +54,6 @@ go_test(
"//beacon-chain/internal:go_default_library",
"//beacon-chain/powchain:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bls:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -71,7 +70,7 @@ func (c *ChainService) ReceiveBlock(ctx context.Context, block *pb.BeaconBlock)
return nil, fmt.Errorf("could not retrieve beacon state: %v", err)
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return nil, fmt.Errorf("could not hash beacon block")
}
@@ -160,7 +159,7 @@ func (c *ChainService) VerifyBlockValidity(
// peers via p2p. Blocks which have already been saved are not processed again via p2p, which is why
// the order of operations is important in this function to prevent infinite p2p loops.
func (c *ChainService) SaveAndBroadcastBlock(ctx context.Context, block *pb.BeaconBlock) error {
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return fmt.Errorf("could not tree hash incoming block: %v", err)
}
@@ -239,7 +238,7 @@ func (c *ChainService) AdvanceState(
"slotsSinceGenesis", newState.Slot,
).Info("Block transition successfully processed")
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return nil, err
}

View File

@@ -17,7 +17,6 @@ import (
v "github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -73,7 +72,7 @@ func TestReceiveBlock_FaultyPOWChain(t *testing.T) {
Slot: 1,
}
parentRoot, err := blockutil.BlockSigningRoot(parentBlock)
parentRoot, err := ssz.HashTreeRoot(parentBlock)
if err != nil {
t.Fatalf("Unable to tree hash block %v", err)
}
@@ -131,7 +130,7 @@ func TestReceiveBlock_ProcessCorrectly(t *testing.T) {
if err := chainService.beaconDB.SaveBlock(genesis); err != nil {
t.Fatalf("Could not save block to db: %v", err)
}
parentRoot, err := blockutil.BlockSigningRoot(genesis)
parentRoot, err := ssz.HashTreeRoot(genesis)
if err != nil {
t.Fatal(err)
}
@@ -302,7 +301,7 @@ func TestReceiveBlock_DeletesBadBlock(t *testing.T) {
},
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatal(err)
}
@@ -368,7 +367,7 @@ func TestReceiveBlock_CheckBlockStateRoot_GoodState(t *testing.T) {
}
beaconState.Slot++
parentRoot, err := blockutil.BlockSigningRoot(genesisBlock)
parentRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}
@@ -432,7 +431,7 @@ func TestReceiveBlock_CheckBlockStateRoot_BadState(t *testing.T) {
}
beaconState.Slot++
parentRoot, err := blockutil.BlockSigningRoot(genesis)
parentRoot, err := ssz.HashTreeRoot(genesis)
if err != nil {
t.Fatal(err)
}
@@ -543,7 +542,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
t.Fatal(err)
}
parentRoot, err := blockutil.BlockSigningRoot(genesis)
parentRoot, err := ssz.HashTreeRoot(genesis)
if err != nil {
t.Fatal(err)
}
@@ -569,7 +568,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
}
initBlockStateRoot(t, block, chainService)
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
log.Fatalf("could not hash block: %v", err)
}
@@ -686,7 +685,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
}
genesisSlot := uint64(0)
parentRoot, err := blockutil.BlockSigningRoot(genesisBlock)
parentRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}
@@ -723,7 +722,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
if err = db.UpdateChainHead(ctx, block, computedState); err != nil {
t.Fatal(err)
}
parentRoot, err = blockutil.BlockSigningRoot(block)
parentRoot, err = ssz.HashTreeRoot(block)
if err != nil {
t.Fatal(err)
}
@@ -735,7 +734,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
t.Fatal(err)
}
parentRoot, err = blockutil.BlockSigningRoot(commonAncestor)
parentRoot, err = ssz.HashTreeRoot(commonAncestor)
if err != nil {
t.Fatal(err)
}
@@ -765,7 +764,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
RandaoReveal: randaoReveal,
},
}
rootF, _ := blockutil.BlockSigningRoot(blockF)
rootF, _ := ssz.HashTreeRoot(blockF)
if err := db.SaveHistoricalState(ctx, beaconState, rootF); err != nil {
t.Fatal(err)
}
@@ -785,7 +784,7 @@ func TestReceiveBlock_OnChainSplit(t *testing.T) {
t.Fatal(err)
}
parentRoot, err = blockutil.BlockSigningRoot(blockF)
parentRoot, err = ssz.HashTreeRoot(blockF)
if err != nil {
t.Fatal(err)
}
@@ -861,7 +860,7 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) {
if err := chainService.beaconDB.SaveBlock(genesis); err != nil {
t.Fatalf("cannot save block: %v", err)
}
parentRoot, err := blockutil.BlockSigningRoot(genesis)
parentRoot, err := ssz.HashTreeRoot(genesis)
if err != nil {
t.Fatalf("unable to get root of canonical head: %v", err)
}

View File

@@ -8,11 +8,11 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/cache"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
@@ -67,7 +67,7 @@ func (c *ChainService) updateFFGCheckPts(ctx context.Context, state *pb.BeaconSt
}
}
newJustifiedRoot, err := blockutil.BlockSigningRoot(newJustifiedBlock)
newJustifiedRoot, err := ssz.HashTreeRoot(newJustifiedBlock)
if err != nil {
return err
}
@@ -109,7 +109,7 @@ func (c *ChainService) updateFFGCheckPts(ctx context.Context, state *pb.BeaconSt
}
}
newFinalizedRoot, err := blockutil.BlockSigningRoot(newFinalizedBlock)
newFinalizedRoot, err := ssz.HashTreeRoot(newFinalizedBlock)
if err != nil {
return err
}
@@ -159,7 +159,7 @@ func (c *ChainService) ApplyForkChoiceRule(
if err != nil {
return fmt.Errorf("could not run fork choice: %v", err)
}
newHeadRoot, err := blockutil.BlockSigningRoot(newHead)
newHeadRoot, err := ssz.HashTreeRoot(newHead)
if err != nil {
return fmt.Errorf("could not hash new head block: %v", err)
}
@@ -171,7 +171,7 @@ func (c *ChainService) ApplyForkChoiceRule(
if err != nil {
return fmt.Errorf("could not retrieve chain head: %v", err)
}
currentHeadRoot, err := blockutil.BlockSigningRoot(currentHead)
currentHeadRoot, err := ssz.HashTreeRoot(currentHead)
if err != nil {
return fmt.Errorf("could not hash current head block: %v", err)
}
@@ -219,7 +219,7 @@ func (c *ChainService) ApplyForkChoiceRule(
if err := c.beaconDB.UpdateChainHead(ctx, newHead, newState); err != nil {
return fmt.Errorf("failed to update chain: %v", err)
}
h, err := blockutil.BlockSigningRoot(newHead)
h, err := ssz.HashTreeRoot(newHead)
if err != nil {
return fmt.Errorf("could not hash head: %v", err)
}
@@ -287,11 +287,11 @@ func (c *ChainService) lmdGhost(
if err != nil {
return nil, fmt.Errorf("unable to determine vote count for block: %v", err)
}
maxChildRoot, err := blockutil.BlockSigningRoot(maxChild)
maxChildRoot, err := ssz.HashTreeRoot(maxChild)
if err != nil {
return nil, err
}
candidateChildRoot, err := blockutil.BlockSigningRoot(children[i])
candidateChildRoot, err := ssz.HashTreeRoot(children[i])
if err != nil {
return nil, err
}
@@ -317,7 +317,7 @@ func (c *ChainService) lmdGhost(
// get_children(store: Store, block: BeaconBlock) -> List[BeaconBlock]
// returns the child blocks of the given block.
func (c *ChainService) BlockChildren(ctx context.Context, block *pb.BeaconBlock, highestSlot uint64) ([]*pb.BeaconBlock, error) {
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return nil, err
}
@@ -343,7 +343,7 @@ func (c *ChainService) BlockChildren(ctx context.Context, block *pb.BeaconBlock,
// isDescendant checks if the new head block is a descendant block of the current head.
func (c *ChainService) isDescendant(currentHead *pb.BeaconBlock, newHead *pb.BeaconBlock) (bool, error) {
currentHeadRoot, err := blockutil.BlockSigningRoot(currentHead)
currentHeadRoot, err := ssz.HashTreeRoot(currentHead)
if err != nil {
return false, nil
}
@@ -400,7 +400,7 @@ func VoteCount(block *pb.BeaconBlock, state *pb.BeaconState, targets map[uint64]
var ancestorRoot []byte
var err error
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return 0, err
}

View File

@@ -5,10 +5,10 @@ import (
"testing"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"
@@ -166,7 +166,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[0], err = blockutil.BlockSigningRoot(blocks[0])
roots[0], err = ssz.HashTreeRoot(blocks[0])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -178,7 +178,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[1], err = blockutil.BlockSigningRoot(blocks[1])
roots[1], err = ssz.HashTreeRoot(blocks[1])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -190,7 +190,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[2], err = blockutil.BlockSigningRoot(blocks[2])
roots[2], err = ssz.HashTreeRoot(blocks[2])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -202,7 +202,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[3], err = blockutil.BlockSigningRoot(blocks[3])
roots[3], err = ssz.HashTreeRoot(blocks[3])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -214,7 +214,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[4], err = blockutil.BlockSigningRoot(blocks[4])
roots[4], err = ssz.HashTreeRoot(blocks[4])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -226,7 +226,7 @@ func constructForkedChain(t *testing.T, beaconState *pb.BeaconState) ([]*pb.Beac
Eth1Data: &pb.Eth1Data{},
},
}
roots[5], err = blockutil.BlockSigningRoot(blocks[5])
roots[5], err = ssz.HashTreeRoot(blocks[5])
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}

View File

@@ -18,7 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -113,7 +112,7 @@ func TestApplyForkChoice_SetsCanonicalHead(t *testing.T) {
StateRoot: stateRoot[:],
ParentRoot: genesisRoot[:],
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatal(err)
}
@@ -147,7 +146,7 @@ func TestVoteCount_ParentDoesNotExistNoVoteCount(t *testing.T) {
if err := beaconDB.SaveBlock(potentialHead); err != nil {
t.Fatal(err)
}
headRoot, err := blockutil.BlockSigningRoot(potentialHead)
headRoot, err := ssz.HashTreeRoot(potentialHead)
if err != nil {
t.Fatal(err)
}
@@ -171,7 +170,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) {
beaconDB := internal.SetupDB(t)
defer internal.TeardownDB(t, beaconDB)
genesisBlock := b.NewGenesisBlock([]byte("stateroot"))
genesisRoot, err := blockutil.BlockSigningRoot(genesisBlock)
genesisRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}
@@ -183,7 +182,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) {
Slot: 5,
ParentRoot: genesisRoot[:],
}
headRoot1, err := blockutil.BlockSigningRoot(potentialHead)
headRoot1, err := ssz.HashTreeRoot(potentialHead)
if err != nil {
t.Fatal(err)
}
@@ -192,7 +191,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) {
Slot: 6,
ParentRoot: genesisRoot[:],
}
headRoot2, err := blockutil.BlockSigningRoot(potentialHead2)
headRoot2, err := ssz.HashTreeRoot(potentialHead2)
if err != nil {
t.Fatal(err)
}
@@ -246,7 +245,7 @@ func TestAttestationTargets_RetrieveWorks(t *testing.T) {
if err := beaconDB.SaveBlock(block); err != nil {
t.Fatalf("could not save block: %v", err)
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatalf("could not hash block: %v", err)
}
@@ -298,7 +297,7 @@ func TestBlockChildren_2InARow(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -313,7 +312,7 @@ func TestBlockChildren_2InARow(t *testing.T) {
Slot: 2,
ParentRoot: root1[:],
}
root2, err := blockutil.BlockSigningRoot(block2)
root2, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -368,7 +367,7 @@ func TestBlockChildren_ChainSplits(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -443,7 +442,7 @@ func TestBlockChildren_SkipSlots(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -458,7 +457,7 @@ func TestBlockChildren_SkipSlots(t *testing.T) {
Slot: 5,
ParentRoot: root1[:],
}
root2, err := blockutil.BlockSigningRoot(block5)
root2, err := ssz.HashTreeRoot(block5)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -513,7 +512,7 @@ func TestLMDGhost_TrivialHeadUpdate(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -528,7 +527,7 @@ func TestLMDGhost_TrivialHeadUpdate(t *testing.T) {
Slot: 2,
ParentRoot: root1[:],
}
block2Root, err := blockutil.BlockSigningRoot(block2)
block2Root, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatal(err)
}
@@ -587,7 +586,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -602,7 +601,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
Slot: 2,
ParentRoot: root1[:],
}
root2, err := blockutil.BlockSigningRoot(block2)
root2, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -617,7 +616,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
Slot: 3,
ParentRoot: root1[:],
}
root3, err := blockutil.BlockSigningRoot(block3)
root3, err := ssz.HashTreeRoot(block3)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -632,7 +631,7 @@ func TestLMDGhost_3WayChainSplitsSameHeight(t *testing.T) {
Slot: 4,
ParentRoot: root1[:],
}
root4, err := blockutil.BlockSigningRoot(block4)
root4, err := ssz.HashTreeRoot(block4)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -694,7 +693,7 @@ func TestIsDescendant_Ok(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -705,7 +704,7 @@ func TestIsDescendant_Ok(t *testing.T) {
Slot: 2,
ParentRoot: root1[:],
}
root2, err := blockutil.BlockSigningRoot(block2)
root2, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -716,7 +715,7 @@ func TestIsDescendant_Ok(t *testing.T) {
Slot: 3,
ParentRoot: root2[:],
}
_, err = blockutil.BlockSigningRoot(block3)
_, err = ssz.HashTreeRoot(block3)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -727,7 +726,7 @@ func TestIsDescendant_Ok(t *testing.T) {
Slot: 4,
ParentRoot: root1[:],
}
root4, err := blockutil.BlockSigningRoot(block4)
root4, err := ssz.HashTreeRoot(block4)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -738,7 +737,7 @@ func TestIsDescendant_Ok(t *testing.T) {
Slot: 5,
ParentRoot: root4[:],
}
_, err = blockutil.BlockSigningRoot(block5)
_, err = ssz.HashTreeRoot(block5)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -792,7 +791,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 1,
ParentRoot: []byte{'A'},
}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -807,7 +806,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 2,
ParentRoot: root1[:],
}
root2, err := blockutil.BlockSigningRoot(block2)
root2, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -822,7 +821,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 3,
ParentRoot: root1[:],
}
root3, err := blockutil.BlockSigningRoot(block3)
root3, err := ssz.HashTreeRoot(block3)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -837,7 +836,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 4,
ParentRoot: root2[:],
}
root4, err := blockutil.BlockSigningRoot(block4)
root4, err := ssz.HashTreeRoot(block4)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -852,7 +851,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 5,
ParentRoot: root3[:],
}
root5, err := blockutil.BlockSigningRoot(block5)
root5, err := ssz.HashTreeRoot(block5)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -867,7 +866,7 @@ func TestLMDGhost_2WayChainSplitsDiffHeight(t *testing.T) {
Slot: 6,
ParentRoot: root4[:],
}
root6, err := blockutil.BlockSigningRoot(block6)
root6, err := ssz.HashTreeRoot(block6)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -932,7 +931,7 @@ func BenchmarkLMDGhost_8Slots_8Validators(b *testing.B) {
Slot: 0,
ParentRoot: []byte{},
}
root, err := blockutil.BlockSigningRoot(genesis)
root, err := ssz.HashTreeRoot(genesis)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
@@ -955,13 +954,13 @@ func BenchmarkLMDGhost_8Slots_8Validators(b *testing.B) {
if err = chainService.beaconDB.UpdateChainHead(ctx, block, beaconState); err != nil {
b.Fatalf("Could update chain head: %v", err)
}
root, err = blockutil.BlockSigningRoot(block)
root, err = ssz.HashTreeRoot(block)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
b.Fatal(err)
}
@@ -1013,7 +1012,7 @@ func BenchmarkLMDGhost_32Slots_8Validators(b *testing.B) {
Slot: 0,
ParentRoot: []byte{},
}
root, err := blockutil.BlockSigningRoot(genesis)
root, err := ssz.HashTreeRoot(genesis)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
@@ -1036,13 +1035,13 @@ func BenchmarkLMDGhost_32Slots_8Validators(b *testing.B) {
if err = chainService.beaconDB.UpdateChainHead(ctx, block, beaconState); err != nil {
b.Fatalf("Could update chain head: %v", err)
}
root, err = blockutil.BlockSigningRoot(block)
root, err = ssz.HashTreeRoot(block)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
b.Fatal(err)
}
@@ -1092,7 +1091,7 @@ func BenchmarkLMDGhost_32Slots_64Validators(b *testing.B) {
Slot: 0,
ParentRoot: []byte{},
}
root, err := blockutil.BlockSigningRoot(genesis)
root, err := ssz.HashTreeRoot(genesis)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
@@ -1115,13 +1114,13 @@ func BenchmarkLMDGhost_32Slots_64Validators(b *testing.B) {
if err = chainService.beaconDB.UpdateChainHead(ctx, block, beaconState); err != nil {
b.Fatalf("Could update chain head: %v", err)
}
root, err = blockutil.BlockSigningRoot(block)
root, err = ssz.HashTreeRoot(block)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
b.Fatal(err)
}
@@ -1171,7 +1170,7 @@ func BenchmarkLMDGhost_64Slots_16384Validators(b *testing.B) {
Slot: 0,
ParentRoot: []byte{},
}
root, err := blockutil.BlockSigningRoot(genesis)
root, err := ssz.HashTreeRoot(genesis)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
@@ -1194,13 +1193,13 @@ func BenchmarkLMDGhost_64Slots_16384Validators(b *testing.B) {
if err = chainService.beaconDB.UpdateChainHead(ctx, block, beaconState); err != nil {
b.Fatalf("Could update chain head: %v", err)
}
root, err = blockutil.BlockSigningRoot(block)
root, err = ssz.HashTreeRoot(block)
if err != nil {
b.Fatalf("Could not hash block: %v", err)
}
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
b.Fatal(err)
}
@@ -1528,7 +1527,7 @@ func setupFFGTest(t *testing.T) ([32]byte, *pb.BeaconBlock, *pb.BeaconState, []*
validatorBalances = append(validatorBalances, params.BeaconConfig().MaxEffectiveBalance)
}
gBlock := &pb.BeaconBlock{Slot: genesisSlot}
gBlockRoot, err := blockutil.BlockSigningRoot(gBlock)
gBlockRoot, err := ssz.HashTreeRoot(gBlock)
if err != nil {
t.Fatal(err)
}
@@ -1562,7 +1561,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) {
beaconDB := internal.SetupDB(t)
defer internal.TeardownDB(t, beaconDB)
genesisBlock := b.NewGenesisBlock([]byte("stateroot"))
genesisRoot, err := blockutil.BlockSigningRoot(genesisBlock)
genesisRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}
@@ -1574,7 +1573,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) {
Slot: 5,
ParentRoot: genesisRoot[:],
}
pHeadHash, err := blockutil.BlockSigningRoot(potentialHead)
pHeadHash, err := ssz.HashTreeRoot(potentialHead)
if err != nil {
t.Fatal(err)
}
@@ -1582,7 +1581,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) {
Slot: 6,
ParentRoot: genesisRoot[:],
}
pHeadHash2, err := blockutil.BlockSigningRoot(potentialHead2)
pHeadHash2, err := ssz.HashTreeRoot(potentialHead2)
if err != nil {
t.Fatal(err)
}
@@ -1614,7 +1613,7 @@ func TestVoteCount_CacheEnabledAndMiss(t *testing.T) {
}
// Verify block ancestor was correctly cached.
h, _ := blockutil.BlockSigningRoot(potentialHead)
h, _ := ssz.HashTreeRoot(potentialHead)
cachedInfo, err := blkAncestorCache.AncestorBySlot(h[:], genesisBlock.Slot)
if err != nil {
t.Fatal(err)
@@ -1629,7 +1628,7 @@ func TestVoteCount_CacheEnabledAndHit(t *testing.T) {
beaconDB := internal.SetupDB(t)
defer internal.TeardownDB(t, beaconDB)
genesisBlock := b.NewGenesisBlock([]byte("stateroot"))
genesisRoot, err := blockutil.BlockSigningRoot(genesisBlock)
genesisRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}
@@ -1641,12 +1640,12 @@ func TestVoteCount_CacheEnabledAndHit(t *testing.T) {
Slot: 5,
ParentRoot: genesisRoot[:],
}
pHeadHash, _ := blockutil.BlockSigningRoot(potentialHead)
pHeadHash, _ := ssz.HashTreeRoot(potentialHead)
potentialHead2 := &pb.BeaconBlock{
Slot: 6,
ParentRoot: genesisRoot[:],
}
pHeadHash2, _ := blockutil.BlockSigningRoot(potentialHead2)
pHeadHash2, _ := ssz.HashTreeRoot(potentialHead2)
// We store these potential heads in the DB.
if err := beaconDB.SaveBlock(potentialHead); err != nil {

View File

@@ -18,7 +18,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/operations"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/sirupsen/logrus"
@@ -147,7 +146,7 @@ func (c *ChainService) initializeBeaconChain(genesisTime time.Time, deposits []*
return nil, fmt.Errorf("could not hash beacon state: %v", err)
}
genBlock := b.NewGenesisBlock(stateRoot[:])
genBlockRoot, err := blockutil.BlockSigningRoot(genBlock)
genBlockRoot, err := ssz.HashTreeRoot(genBlock)
if err != nil {
return nil, fmt.Errorf("could not hash beacon block: %v", err)
}
@@ -217,7 +216,7 @@ func (c *ChainService) ChainHeadRoot() ([32]byte, error) {
return [32]byte{}, fmt.Errorf("could not retrieve chain head: %v", err)
}
root, err := blockutil.BlockSigningRoot(head)
root, err := ssz.HashTreeRoot(head)
if err != nil {
return [32]byte{}, fmt.Errorf("could not tree hash parent block: %v", err)
}

View File

@@ -12,13 +12,13 @@ import (
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/attestation"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/p2p"
@@ -165,7 +165,7 @@ func setupGenesisBlock(t *testing.T, cs *ChainService) ([32]byte, *pb.BeaconBloc
if err := cs.beaconDB.SaveBlock(genesis); err != nil {
t.Fatalf("could not save block to db: %v", err)
}
parentHash, err := blockutil.BlockSigningRoot(genesis)
parentHash, err := ssz.HashTreeRoot(genesis)
if err != nil {
t.Fatalf("unable to get tree hash root of canonical head: %v", err)
}

View File

@@ -13,7 +13,6 @@ go_library(
"//beacon-chain/core/epoch:go_default_library",
"//beacon-chain/core/helpers:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/mathutil:go_default_library",

View File

@@ -13,7 +13,6 @@ import (
e "github.com/prysmaticlabs/prysm/beacon-chain/core/epoch"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -205,7 +204,7 @@ func ProcessBlock(
return nil, fmt.Errorf("could not process block operation: %v", err)
}
r, err := blockutil.BlockSigningRoot(block)
r, err := ssz.HashTreeRoot(block)
if err != nil {
return nil, fmt.Errorf("could not hash block: %v", err)
}

View File

@@ -22,7 +22,6 @@ go_library(
"//beacon-chain/core/blocks:go_default_library",
"//beacon-chain/core/state:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
@@ -54,7 +53,6 @@ go_test(
embed = [":go_default_library"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
@@ -62,5 +60,6 @@ go_test(
"@com_github_boltdb_bolt//:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)

View File

@@ -10,8 +10,8 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"go.opencensus.io/trace"
)
@@ -134,7 +134,7 @@ func (db *BeaconDB) SaveBlock(block *pb.BeaconBlock) error {
db.blocksLock.Lock()
defer db.blocksLock.Unlock()
signingRoot, err := blockutil.BlockSigningRoot(block)
signingRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash header: %v", err)
}
@@ -171,7 +171,7 @@ func (db *BeaconDB) DeleteBlock(block *pb.BeaconBlock) error {
db.blocksLock.Lock()
defer db.blocksLock.Unlock()
signingRoot, err := blockutil.BlockSigningRoot(block)
signingRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash block: %v", err)
}
@@ -285,7 +285,7 @@ func (db *BeaconDB) UpdateChainHead(ctx context.Context, block *pb.BeaconBlock,
ctx, span := trace.StartSpan(ctx, "beacon-chain.db.UpdateChainHead")
defer span.End()
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return fmt.Errorf("unable to determine block signing root: %v", err)
}

View File

@@ -7,8 +7,8 @@ import (
"time"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
@@ -25,7 +25,7 @@ func TestNilDB_OK(t *testing.T) {
defer teardownDB(t, db)
block := &pb.BeaconBlock{}
h, _ := blockutil.BlockSigningRoot(block)
h, _ := ssz.HashTreeRoot(block)
hasBlock := db.HasBlock(h)
if hasBlock {
@@ -46,7 +46,7 @@ func TestSaveBlock_OK(t *testing.T) {
defer teardownDB(t, db)
block1 := &pb.BeaconBlock{}
h1, _ := blockutil.BlockSigningRoot(block1)
h1, _ := ssz.HashTreeRoot(block1)
err := db.SaveBlock(block1)
if err != nil {
@@ -57,7 +57,7 @@ func TestSaveBlock_OK(t *testing.T) {
if err != nil {
t.Fatalf("failed to get block: %v", err)
}
h1Prime, _ := blockutil.BlockSigningRoot(b1Prime)
h1Prime, _ := ssz.HashTreeRoot(b1Prime)
if b1Prime == nil || h1 != h1Prime {
t.Fatalf("get should return b1: %x", h1)
@@ -66,7 +66,7 @@ func TestSaveBlock_OK(t *testing.T) {
block2 := &pb.BeaconBlock{
Slot: 0,
}
h2, _ := blockutil.BlockSigningRoot(block2)
h2, _ := ssz.HashTreeRoot(block2)
err = db.SaveBlock(block2)
if err != nil {
@@ -77,7 +77,7 @@ func TestSaveBlock_OK(t *testing.T) {
if err != nil {
t.Fatalf("failed to get block: %v", err)
}
h2Prime, _ := blockutil.BlockSigningRoot(b2Prime)
h2Prime, _ := ssz.HashTreeRoot(b2Prime)
if b2Prime == nil || h2 != h2Prime {
t.Fatalf("get should return b2: %x", h2)
}
@@ -88,7 +88,7 @@ func TestSaveBlock_NilBlkInCache(t *testing.T) {
defer teardownDB(t, db)
block := &pb.BeaconBlock{Slot: 999}
h1, _ := blockutil.BlockSigningRoot(block)
h1, _ := ssz.HashTreeRoot(block)
// Save a nil block to with block root.
db.blocks[h1] = nil
@@ -116,7 +116,7 @@ func TestSaveBlockInCache_OK(t *testing.T) {
defer teardownDB(t, db)
block := &pb.BeaconBlock{Slot: 999}
h, _ := blockutil.BlockSigningRoot(block)
h, _ := ssz.HashTreeRoot(block)
err := db.SaveBlock(block)
if err != nil {
@@ -141,7 +141,7 @@ func TestDeleteBlock_OK(t *testing.T) {
defer teardownDB(t, db)
block := &pb.BeaconBlock{Slot: 0}
h, _ := blockutil.BlockSigningRoot(block)
h, _ := ssz.HashTreeRoot(block)
err := db.SaveBlock(block)
if err != nil {
@@ -172,7 +172,7 @@ func TestDeleteBlockInCache_OK(t *testing.T) {
defer teardownDB(t, db)
block := &pb.BeaconBlock{Slot: 0}
h, _ := blockutil.BlockSigningRoot(block)
h, _ := ssz.HashTreeRoot(block)
err := db.SaveBlock(block)
if err != nil {
@@ -278,7 +278,7 @@ func TestUpdateChainHead_OK(t *testing.T) {
if err != nil {
t.Fatalf("failed to get genesis block: %v", err)
}
bHash, err := blockutil.BlockSigningRoot(block)
bHash, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatalf("failed to get hash of b: %v", err)
}
@@ -292,7 +292,7 @@ func TestUpdateChainHead_OK(t *testing.T) {
Slot: 1,
ParentRoot: bHash[:],
}
b2Hash, err := blockutil.BlockSigningRoot(block2)
b2Hash, err := ssz.HashTreeRoot(block2)
if err != nil {
t.Fatalf("failed to hash b2: %v", err)
}
@@ -312,11 +312,11 @@ func TestUpdateChainHead_OK(t *testing.T) {
t.Fatalf("failed to retrieve head: %v", err)
}
b2PrimeHash, err := blockutil.BlockSigningRoot(b2Prime)
b2PrimeHash, err := ssz.HashTreeRoot(b2Prime)
if err != nil {
t.Fatalf("failed to hash b2Prime: %v", err)
}
b2SigmaHash, err := blockutil.BlockSigningRoot(b2Sigma)
b2SigmaHash, err := ssz.HashTreeRoot(b2Sigma)
if err != nil {
t.Fatalf("failed to hash b2Sigma: %v", err)
}
@@ -467,7 +467,7 @@ func TestHasBlock_returnsTrue(t *testing.T) {
Slot: uint64(44),
}
root, err := blockutil.BlockSigningRoot(block)
root, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatal(err)
}

View File

@@ -15,7 +15,6 @@ import (
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"go.opencensus.io/trace"
@@ -44,7 +43,7 @@ func (db *BeaconDB) InitializeState(ctx context.Context, genesisTime uint64, dep
stateHash := hashutil.Hash(stateEnc)
genesisBlock := b.NewGenesisBlock(stateHash[:])
// #nosec G104
blockRoot, _ := blockutil.BlockSigningRoot(genesisBlock)
blockRoot, _ := ssz.HashTreeRoot(genesisBlock)
// #nosec G104
blockEnc, _ := proto.Marshal(genesisBlock)
zeroBinary := encodeSlotNumberRoot(0, blockRoot)

View File

@@ -9,7 +9,6 @@ go_library(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
@@ -17,6 +16,7 @@ go_library(
"//shared/p2p:go_default_library",
"//shared/params:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],
@@ -31,11 +31,11 @@ go_test(
"//beacon-chain/core/helpers:go_default_library",
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],

View File

@@ -8,10 +8,10 @@ import (
"sort"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -239,7 +239,7 @@ func (s *Service) IsAttCanonical(ctx context.Context, att *pb.Attestation) (bool
if canonicalBlk == nil {
return false, nil
}
canonicalRoot, err := blockutil.BlockSigningRoot(canonicalBlk)
canonicalRoot, err := ssz.HashTreeRoot(canonicalBlk)
if err != nil {
return false, fmt.Errorf("could not hash block: %v", err)
}

View File

@@ -9,10 +9,10 @@ import (
"testing"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
@@ -328,7 +328,7 @@ func TestIsCanonical_CanGetCanonical(t *testing.T) {
if err := s.beaconDB.UpdateChainHead(context.Background(), cb1, &pb.BeaconState{}); err != nil {
t.Fatal(err)
}
r1, err := blockutil.BlockSigningRoot(cb1)
r1, err := ssz.HashTreeRoot(cb1)
if err != nil {
t.Fatal(err)
}
@@ -374,7 +374,7 @@ func TestIsCanonical_NilBlocks(t *testing.T) {
if err := s.beaconDB.SaveBlock(cb1); err != nil {
t.Fatal(err)
}
r1, err := blockutil.BlockSigningRoot(cb1)
r1, err := ssz.HashTreeRoot(cb1)
if err != nil {
t.Fatal(err)
}

View File

@@ -21,7 +21,6 @@ go_library(
"//beacon-chain/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
@@ -64,7 +63,6 @@ go_test(
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//proto/beacon/rpc/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
@@ -113,7 +112,7 @@ func (as *AttesterServer) RequestAttestation(ctx context.Context, req *pb.Attest
if err != nil {
return nil, fmt.Errorf("failed to retrieve chain head: %v", err)
}
headRoot, err := blockutil.BlockSigningRoot(headBlock)
headRoot, err := ssz.HashTreeRoot(headBlock)
if err != nil {
return nil, fmt.Errorf("could not tree hash beacon block: %v", err)
}

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
@@ -38,7 +37,7 @@ func TestSubmitAttestation_OK(t *testing.T) {
if err := attesterServer.beaconDB.SaveBlock(head); err != nil {
t.Fatal(err)
}
root, err := blockutil.BlockSigningRoot(head)
root, err := ssz.HashTreeRoot(head)
if err != nil {
t.Fatal(err)
}
@@ -92,15 +91,15 @@ func TestRequestAttestation_OK(t *testing.T) {
justifiedBlock := &pbp2p.BeaconBlock{
Slot: 2 * params.BeaconConfig().SlotsPerEpoch,
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatalf("Could not hash beacon block: %v", err)
}
justifiedRoot, err := blockutil.BlockSigningRoot(justifiedBlock)
justifiedRoot, err := ssz.HashTreeRoot(justifiedBlock)
if err != nil {
t.Fatalf("Could not get signing root for justified block: %v", err)
}
targetRoot, err := blockutil.BlockSigningRoot(targetBlock)
targetRoot, err := ssz.HashTreeRoot(targetBlock)
if err != nil {
t.Fatalf("Could not get signing root for target block: %v", err)
}
@@ -209,15 +208,15 @@ func TestAttestationDataAtSlot_handlesFarAwayJustifiedEpoch(t *testing.T) {
justifiedBlock := &pbp2p.BeaconBlock{
Slot: helpers.StartSlot(helpers.SlotToEpoch(1500)) - 2, // Imagine two skip block
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatalf("Could not hash beacon block: %v", err)
}
justifiedBlockRoot, err := blockutil.BlockSigningRoot(justifiedBlock)
justifiedBlockRoot, err := ssz.HashTreeRoot(justifiedBlock)
if err != nil {
t.Fatalf("Could not hash justified block: %v", err)
}
epochBoundaryRoot, err := blockutil.BlockSigningRoot(epochBoundaryBlock)
epochBoundaryRoot, err := ssz.HashTreeRoot(epochBoundaryBlock)
if err != nil {
t.Fatalf("Could not hash justified block: %v", err)
}

View File

@@ -9,12 +9,12 @@ import (
"time"
ptypes "github.com/gogo/protobuf/types"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
@@ -115,7 +115,7 @@ func (bs *BeaconServer) BlockTree(ctx context.Context, _ *ptypes.Empty) (*pb.Blo
if err != nil {
return nil, err
}
blockRoot, err := blockutil.BlockSigningRoot(kid)
blockRoot, err := ssz.HashTreeRoot(kid)
if err != nil {
return nil, err
}
@@ -245,7 +245,7 @@ func (bs *BeaconServer) BlockTreeBySlots(ctx context.Context, req *pb.TreeBlockS
if err != nil {
return nil, err
}
blockRoot, err := blockutil.BlockSigningRoot(kid)
blockRoot, err := ssz.HashTreeRoot(kid)
if err != nil {
return nil, err
}

View File

@@ -14,11 +14,11 @@ import (
"github.com/ethereum/go-ethereum/common"
ptypes "github.com/gogo/protobuf/types"
"github.com/golang/mock/gomock"
"github.com/prysmaticlabs/go-ssz"
dbs "github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -593,7 +593,7 @@ func TestBlockTree_OK(t *testing.T) {
if err := db.SaveJustifiedBlock(justifiedBlock); err != nil {
t.Fatal(err)
}
justifiedRoot, _ := blockutil.BlockSigningRoot(justifiedBlock)
justifiedRoot, _ := ssz.HashTreeRoot(justifiedBlock)
balances := []uint64{params.BeaconConfig().MaxEffectiveBalance}
b1 := &pbp2p.BeaconBlock{
@@ -601,7 +601,7 @@ func TestBlockTree_OK(t *testing.T) {
ParentRoot: justifiedRoot[:],
StateRoot: []byte{0x1},
}
b1Root, _ := blockutil.BlockSigningRoot(b1)
b1Root, _ := ssz.HashTreeRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -614,7 +614,7 @@ func TestBlockTree_OK(t *testing.T) {
ParentRoot: justifiedRoot[:],
StateRoot: []byte{0x2},
}
b2Root, _ := blockutil.BlockSigningRoot(b2)
b2Root, _ := ssz.HashTreeRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -627,7 +627,7 @@ func TestBlockTree_OK(t *testing.T) {
ParentRoot: justifiedRoot[:],
StateRoot: []byte{0x3},
}
b3Root, _ := blockutil.BlockSigningRoot(b3)
b3Root, _ := ssz.HashTreeRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -640,7 +640,7 @@ func TestBlockTree_OK(t *testing.T) {
ParentRoot: b1Root[:],
StateRoot: []byte{0x4},
}
b4Root, _ := blockutil.BlockSigningRoot(b4)
b4Root, _ := ssz.HashTreeRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
Validators: validators,
@@ -653,7 +653,7 @@ func TestBlockTree_OK(t *testing.T) {
ParentRoot: b3Root[:],
StateRoot: []byte{0x5},
}
b5Root, _ := blockutil.BlockSigningRoot(b5)
b5Root, _ := ssz.HashTreeRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
Validators: validators,
@@ -809,14 +809,14 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
if err := db.SaveJustifiedBlock(justifiedBlock); err != nil {
t.Fatal(err)
}
justifiedRoot, _ := blockutil.BlockSigningRoot(justifiedBlock)
justifiedRoot, _ := ssz.HashTreeRoot(justifiedBlock)
validators := []*pbp2p.Validator{{ExitEpoch: params.BeaconConfig().FarFutureEpoch}}
balances := []uint64{params.BeaconConfig().MaxEffectiveBalance}
b1 := &pbp2p.BeaconBlock{
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b1Root, _ := blockutil.BlockSigningRoot(b1)
b1Root, _ := ssz.HashTreeRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -828,7 +828,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b2Root, _ := blockutil.BlockSigningRoot(b2)
b2Root, _ := ssz.HashTreeRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -840,7 +840,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b3Root, _ := blockutil.BlockSigningRoot(b3)
b3Root, _ := ssz.HashTreeRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -852,7 +852,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
Slot: 4,
ParentRoot: b1Root[:],
}
b4Root, _ := blockutil.BlockSigningRoot(b4)
b4Root, _ := ssz.HashTreeRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
Validators: validators,
@@ -864,7 +864,7 @@ func TestBlockTreeBySlots_ArgsValildation(t *testing.T) {
Slot: 5,
ParentRoot: b3Root[:],
}
b5Root, _ := blockutil.BlockSigningRoot(b5)
b5Root, _ := ssz.HashTreeRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
Validators: validators,
@@ -1023,13 +1023,13 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
if err := db.SaveJustifiedBlock(justifiedBlock); err != nil {
t.Fatal(err)
}
justifiedRoot, _ := blockutil.BlockSigningRoot(justifiedBlock)
justifiedRoot, _ := ssz.HashTreeRoot(justifiedBlock)
balances := []uint64{params.BeaconConfig().MaxEffectiveBalance}
b1 := &pbp2p.BeaconBlock{
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b1Root, _ := blockutil.BlockSigningRoot(b1)
b1Root, _ := ssz.HashTreeRoot(b1)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -1041,7 +1041,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b2Root, _ := blockutil.BlockSigningRoot(b2)
b2Root, _ := ssz.HashTreeRoot(b2)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -1053,7 +1053,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
Slot: 3,
ParentRoot: justifiedRoot[:],
}
b3Root, _ := blockutil.BlockSigningRoot(b3)
b3Root, _ := ssz.HashTreeRoot(b3)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 3,
Validators: validators,
@@ -1065,7 +1065,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
Slot: 4,
ParentRoot: b1Root[:],
}
b4Root, _ := blockutil.BlockSigningRoot(b4)
b4Root, _ := ssz.HashTreeRoot(b4)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 4,
Validators: validators,
@@ -1077,7 +1077,7 @@ func TestBlockTreeBySlots_OK(t *testing.T) {
Slot: 5,
ParentRoot: b3Root[:],
}
b5Root, _ := blockutil.BlockSigningRoot(b5)
b5Root, _ := ssz.HashTreeRoot(b5)
if err := db.SaveHistoricalState(ctx, &pbp2p.BeaconState{
Slot: 5,
Validators: validators,

View File

@@ -6,13 +6,13 @@ import (
"fmt"
"math/big"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -42,7 +42,7 @@ func (ps *ProposerServer) RequestBlock(ctx context.Context, req *pb.BlockRequest
return nil, fmt.Errorf("could not get canonical head block: %v", err)
}
parentRoot, err := blockutil.BlockSigningRoot(parent)
parentRoot, err := ssz.HashTreeRoot(parent)
if err != nil {
return nil, fmt.Errorf("could not get parent block signing root: %v", err)
}
@@ -99,7 +99,7 @@ func (ps *ProposerServer) RequestBlock(ctx context.Context, req *pb.BlockRequest
// ProposeBlock is called by a proposer during its assigned slot to create a block in an attempt
// to get it processed by the beacon node as the canonical head.
func (ps *ProposerServer) ProposeBlock(ctx context.Context, blk *pbp2p.BeaconBlock) (*pb.ProposeResponse, error) {
root, err := blockutil.BlockSigningRoot(blk)
root, err := ssz.HashTreeRoot(blk)
if err != nil {
return nil, fmt.Errorf("could not tree hash block: %v", err)
}

View File

@@ -18,7 +18,6 @@ go_library(
"//beacon-chain/operations:go_default_library",
"//beacon-chain/sync/initial-sync:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
@@ -29,6 +28,7 @@ go_library(
"@com_github_libp2p_go_libp2p_peer//:go_default_library",
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_opencensus_go//trace:go_default_library",
],
@@ -49,7 +49,6 @@ go_test(
"//beacon-chain/db:go_default_library",
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/featureconfig:go_default_library",
@@ -60,6 +59,7 @@ go_test(
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_libp2p_go_libp2p_peer//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],

View File

@@ -18,7 +18,6 @@ go_library(
"//beacon-chain/core/validators:go_default_library",
"//beacon-chain/db:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/p2p:go_default_library",
@@ -44,13 +43,13 @@ go_test(
"//beacon-chain/db:go_default_library",
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/blockutil:go_default_library",
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/p2p:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_libp2p_go_libp2p_peer//:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
],
)

View File

@@ -21,10 +21,10 @@ import (
"github.com/ethereum/go-ethereum/common"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/p2p"
@@ -169,7 +169,7 @@ func (s *InitialSync) exitInitialSync(ctx context.Context, block *pb.BeaconBlock
if err := s.db.SaveBlock(block); err != nil {
return err
}
root, err := blockutil.BlockSigningRoot(block)
root, err := ssz.HashTreeRoot(block)
if err != nil {
return fmt.Errorf("failed to tree hash block: %v", err)
}

View File

@@ -7,11 +7,11 @@ import (
"github.com/gogo/protobuf/proto"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/prysmaticlabs/go-ssz"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
@@ -168,7 +168,7 @@ func TestProcessingBlocks_SkippedSlots(t *testing.T) {
if err != nil {
t.Fatalf("Unable to get genesis block %v", err)
}
h, err := blockutil.BlockSigningRoot(blks[0])
h, err := ssz.HashTreeRoot(blks[0])
if err != nil {
t.Fatalf("Unable to hash block %v", err)
}
@@ -194,7 +194,7 @@ func TestProcessingBlocks_SkippedSlots(t *testing.T) {
t.Fatalf("Block unable to be saved %v", err)
}
hash, err := blockutil.BlockSigningRoot(block)
hash, err := ssz.HashTreeRoot(block)
if err != nil {
t.Fatalf("Could not hash block %v", err)
}

View File

@@ -7,8 +7,8 @@ import (
"sort"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/sirupsen/logrus"
@@ -94,7 +94,7 @@ func (s *InitialSync) validateAndSaveNextBlock(ctx context.Context, block *pb.Be
if block == nil {
return errors.New("received nil block")
}
root, err := blockutil.BlockSigningRoot(block)
root, err := ssz.HashTreeRoot(block)
if err != nil {
return err
}

View File

@@ -4,9 +4,9 @@ import (
"context"
"fmt"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/params"
@@ -85,7 +85,7 @@ func (rs *RegularSync) processBlockAndFetchAncestors(ctx context.Context, msg p2
return nil
}
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
return err
}
@@ -114,7 +114,7 @@ func (rs *RegularSync) validateAndProcessBlock(
response := blockMsg.Data.(*pb.BeaconBlockResponse)
block := response.Block
blockRoot, err := blockutil.BlockSigningRoot(block)
blockRoot, err := ssz.HashTreeRoot(block)
if err != nil {
log.Errorf("Could not hash received block: %v", err)
span.AddAttributes(trace.BoolAttribute("invalidBlock", true))
@@ -180,7 +180,7 @@ func (rs *RegularSync) validateAndProcessBlock(
return nil, nil, false, err
}
headRoot, err := blockutil.BlockSigningRoot(head)
headRoot, err := ssz.HashTreeRoot(head)
if err != nil {
log.Errorf("Could not hash head block: %v", err)
return nil, nil, false, err

View File

@@ -4,9 +4,9 @@ import (
"context"
"testing"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/testutil"
@@ -34,7 +34,7 @@ func setupBlockParents(t *testing.T, genesisRoot [32]byte) ([]*pb.BeaconBlock, [
} else {
parent.ParentRoot = parentRoots[len(parentRoots)-1][:]
}
parentRoot, err := blockutil.BlockSigningRoot(parent)
parentRoot, err := ssz.HashTreeRoot(parent)
if err != nil {
t.Fatal(err)
}
@@ -104,7 +104,7 @@ func TestReceiveBlock_RecursivelyProcessesChildren(t *testing.T) {
genesisBlock := &pb.BeaconBlock{
Slot: 0,
}
genesisRoot, err := blockutil.BlockSigningRoot(genesisBlock)
genesisRoot, err := ssz.HashTreeRoot(genesisBlock)
if err != nil {
t.Fatal(err)
}

View File

@@ -13,12 +13,12 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/operations"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
@@ -340,7 +340,7 @@ func (rs *RegularSync) handleChainHeadRequest(msg p2p.Message) error {
log.Errorf("Could not retrieve chain head: %v", err)
return err
}
headBlkRoot, err := blockutil.BlockSigningRoot(head)
headBlkRoot, err := ssz.HashTreeRoot(head)
if err != nil {
log.Errorf("Could not hash chain head: %v", err)
}
@@ -349,7 +349,7 @@ func (rs *RegularSync) handleChainHeadRequest(msg p2p.Message) error {
log.Errorf("Could not retrieve finalized block: %v", err)
return err
}
finalizedBlkRoot, err := blockutil.BlockSigningRoot(finalizedBlk)
finalizedBlkRoot, err := ssz.HashTreeRoot(finalizedBlk)
if err != nil {
log.Errorf("Could not hash finalized block: %v", err)
}

View File

@@ -11,11 +11,11 @@ import (
"github.com/gogo/protobuf/proto"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/blockutil"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
@@ -208,7 +208,7 @@ func TestProcessBlock_OK(t *testing.T) {
if err := db.SaveBlock(parentBlock); err != nil {
t.Fatalf("failed to save block: %v", err)
}
parentRoot, err := blockutil.BlockSigningRoot(parentBlock)
parentRoot, err := ssz.HashTreeRoot(parentBlock)
if err != nil {
t.Fatalf("failed to get parent root: %v", err)
}
@@ -286,7 +286,7 @@ func TestProcessBlock_MultipleBlocksProcessedOK(t *testing.T) {
if err := db.SaveBlock(parentBlock); err != nil {
t.Fatalf("failed to save block: %v", err)
}
parentRoot, err := blockutil.BlockSigningRoot(parentBlock)
parentRoot, err := ssz.HashTreeRoot(parentBlock)
if err != nil {
t.Fatalf("failed to get parent root: %v", err)
}
@@ -736,7 +736,7 @@ func TestCanonicalBlockList_CanRetrieveCanonical(t *testing.T) {
// /- B3
// B1 - B2 - B4
block1 := &pb.BeaconBlock{Slot: 1, ParentRoot: []byte{'A'}}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -744,7 +744,7 @@ func TestCanonicalBlockList_CanRetrieveCanonical(t *testing.T) {
t.Fatalf("Could not save block: %v", err)
}
block2 := &pb.BeaconBlock{Slot: 2, ParentRoot: root1[:]}
root2, _ := blockutil.BlockSigningRoot(block2)
root2, _ := ssz.HashTreeRoot(block2)
if err = ss.db.SaveBlock(block2); err != nil {
t.Fatalf("Could not save block: %v", err)
}
@@ -753,7 +753,7 @@ func TestCanonicalBlockList_CanRetrieveCanonical(t *testing.T) {
t.Fatalf("Could not save block: %v", err)
}
block4 := &pb.BeaconBlock{Slot: 4, ParentRoot: root2[:]}
root4, _ := blockutil.BlockSigningRoot(block4)
root4, _ := ssz.HashTreeRoot(block4)
if err = ss.db.SaveBlock(block4); err != nil {
t.Fatalf("Could not save block: %v", err)
}
@@ -774,7 +774,7 @@ func TestCanonicalBlockList_SameFinalizedAndHead(t *testing.T) {
// Construct the following chain:
// B1 (finalized and head)
block1 := &pb.BeaconBlock{Slot: 1, ParentRoot: []byte{'A'}}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}
@@ -806,7 +806,7 @@ func TestCanonicalBlockList_NilParentBlock(t *testing.T) {
ss := setupService(db)
block1 := &pb.BeaconBlock{Slot: 1, ParentRoot: []byte{'B'}}
root1, err := blockutil.BlockSigningRoot(block1)
root1, err := ssz.HashTreeRoot(block1)
if err != nil {
t.Fatalf("Could not hash block: %v", err)
}

View File

@@ -1,12 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = ["beacon_block.go"],
importpath = "github.com/prysmaticlabs/prysm/shared/blockutil",
visibility = ["//visibility:public"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",
"@com_github_prysmaticlabs_go_ssz//:go_default_library",
],
)

View File

@@ -1,24 +0,0 @@
package blockutil
import (
"github.com/prysmaticlabs/go-ssz"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
// BlockSigningRoot uses Simple Serialize (SSZ) to determine the block header signing root
// given a beacon block. This is used as the parent root of subsequent blocks, for verifying
// headers, and also looking up blocks by this root in the DB.
func BlockSigningRoot(bb *pb.BeaconBlock) ([32]byte, error) {
bodyRoot, err := ssz.HashTreeRoot(bb.Body)
if err != nil {
return [32]byte{}, err
}
header := &pb.BeaconBlockHeader{
Slot: bb.Slot,
ParentRoot: bb.ParentRoot,
BodyRoot: bodyRoot[:],
StateRoot: bb.StateRoot,
Signature: bb.Signature,
}
return ssz.SigningRoot(header)
}