Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Usage of ssz.TreeHash Across Repo #1711

Merged
merged 3 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/attestation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ go_test(
"//beacon-chain/internal:go_default_library",
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/ssz:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/testutil:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
Expand Down
5 changes: 3 additions & 2 deletions beacon-chain/attestation/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"strings"
"testing"

"github.com/prysmaticlabs/prysm/shared/hashutil"

"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
Expand Down Expand Up @@ -177,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 := ssz.TreeHash(block)
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
log.Fatalf("could not hash block: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/blockchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ go_library(
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/ssz:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand All @@ -44,8 +44,8 @@ go_test(
"//shared/bytesutil:go_default_library",
"//shared/event:go_default_library",
"//shared/forkutils:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/ssz:go_default_library",
"//shared/testutil:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ethereum_go_ethereum//:go_default_library",
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/blockchain/fork_choice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package blockchain
import (
"fmt"

"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/hashutil"

b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
Expand Down Expand Up @@ -73,11 +73,11 @@ func VoteCount(block *pb.BeaconBlock, state *pb.BeaconState, targets map[uint64]
if err != nil {
return 0, err
}
ancestorRoot, err := ssz.TreeHash(ancestor)
ancestorRoot, err := hashutil.HashBeaconBlock(ancestor)
if err != nil {
return 0, err
}
blockRoot, err := ssz.TreeHash(block)
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
return 0, err
}
Expand Down
9 changes: 5 additions & 4 deletions beacon-chain/blockchain/fork_choice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"testing"
"time"

"github.com/prysmaticlabs/prysm/shared/hashutil"

b "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"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
)

// Generates an initial genesis block and state using a custom number of initial
Expand Down Expand Up @@ -45,15 +46,15 @@ func generateTestGenesisStateAndBlock(
if err := beaconDB.SaveState(beaconState); err != nil {
t.Fatal(err)
}
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatal(err)
}
genesisBlock := b.NewGenesisBlock(stateRoot[:])
if err := beaconDB.SaveBlock(genesisBlock); err != nil {
t.Fatal(err)
}
genesisRoot, err := ssz.TreeHash(genesisBlock)
genesisRoot, err := hashutil.HashBeaconBlock(genesisBlock)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -207,7 +208,7 @@ func TestVoteCount_IncreaseCountCorrectly(t *testing.T) {
beaconDB := internal.SetupDB(t)
defer internal.TeardownDB(t, beaconDB)
genesisBlock := b.NewGenesisBlock([]byte("stateroot"))
genesisRoot, err := ssz.TreeHash(genesisBlock)
genesisRoot, err := hashutil.HashBeaconBlock(genesisBlock)
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 6 additions & 5 deletions beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"time"

"github.com/prysmaticlabs/prysm/shared/hashutil"

"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
Expand All @@ -17,7 +19,6 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -121,7 +122,7 @@ func (c *ChainService) initializeBeaconChain(genesisTime time.Time, deposits []*
if err != nil {
return fmt.Errorf("could not attempt fetch beacon state: %v", err)
}
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
return fmt.Errorf("could not hash beacon state: %v", err)
}
Expand Down Expand Up @@ -177,7 +178,7 @@ func (c *ChainService) ChainHeadRoot() ([32]byte, error) {
return [32]byte{}, fmt.Errorf("could not retrieve chain head: %v", err)
}

root, err := ssz.TreeHash(head)
root, err := hashutil.HashBeaconBlock(head)
if err != nil {
return [32]byte{}, fmt.Errorf("could not tree hash parent block: %v", err)
}
Expand Down Expand Up @@ -234,7 +235,7 @@ func (c *ChainService) blockProcessing() {
// ApplyForkChoiceRule determines the current beacon chain head using LMD GHOST as a block-vote
// weighted function to select a canonical head in Ethereum Serenity.
func (c *ChainService) ApplyForkChoiceRule(block *pb.BeaconBlock, computedState *pb.BeaconState) error {
h, err := ssz.TreeHash(block)
h, err := hashutil.HashBeaconBlock(block)
if err != nil {
return fmt.Errorf("could not tree hash incoming block: %v", err)
}
Expand Down Expand Up @@ -280,7 +281,7 @@ func (c *ChainService) ApplyForkChoiceRule(block *pb.BeaconBlock, computedState
// return nil, error # or throw or whatever
//
func (c *ChainService) ReceiveBlock(block *pb.BeaconBlock, beaconState *pb.BeaconState) (*pb.BeaconState, error) {
blockRoot, err := ssz.TreeHash(block)
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
return nil, fmt.Errorf("could not tree hash incoming block: %v", err)
}
Expand Down
21 changes: 11 additions & 10 deletions beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"testing"
"time"

"github.com/prysmaticlabs/prysm/shared/hashutil"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
gethTypes "github.com/ethereum/go-ethereum/core/types"
Expand All @@ -25,7 +27,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/forkutils"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/trieutil"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -181,7 +182,7 @@ func setupGenesisBlock(t *testing.T, cs *ChainService, beaconState *pb.BeaconSta
if err := cs.beaconDB.SaveBlock(genesis); err != nil {
t.Fatalf("could not save block to db: %v", err)
}
parentHash, err := ssz.TreeHash(genesis)
parentHash, err := hashutil.HashBeaconBlock(genesis)
if err != nil {
t.Fatalf("unable to get tree hash root of canonical head: %v", err)
}
Expand Down Expand Up @@ -349,7 +350,7 @@ func TestChainService_FaultyPOWChain(t *testing.T) {
Slot: 1,
}

parentRoot, err := ssz.TreeHash(parentBlock)
parentRoot, err := hashutil.HashBeaconBlock(parentBlock)
if err != nil {
t.Fatalf("Unable to tree hash block %v", err)
}
Expand Down Expand Up @@ -394,7 +395,7 @@ func TestChainService_Starts(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("Could not tree hash state: %v", err)
}
Expand Down Expand Up @@ -449,7 +450,7 @@ func TestReceiveBlock_RemovesPendingDeposits(t *testing.T) {
if err != nil {
t.Fatalf("Can't generate genesis state: %v", err)
}
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("Could not tree hash state: %v", err)
}
Expand Down Expand Up @@ -540,13 +541,13 @@ func TestUpdateHead_SavesBlock(t *testing.T) {
if err != nil {
t.Fatalf("Cannot create genesis beacon state: %v", err)
}
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("Could not tree hash state: %v", err)
}

genesis := b.NewGenesisBlock(stateRoot[:])
genesisRoot, err := ssz.TreeHash(genesis)
genesisRoot, err := hashutil.HashProto(genesis)
if err != nil {
t.Fatalf("Could not get genesis block root: %v", err)
}
Expand Down Expand Up @@ -590,7 +591,7 @@ func TestUpdateHead_SavesBlock(t *testing.T) {
t.Fatalf("Could not initialize beacon state to disk: %v", err)
}

stateRoot, err := ssz.TreeHash(tt.state)
stateRoot, err := hashutil.HashProto(tt.state)
if err != nil {
t.Fatalf("Could not tree hash state: %v", err)
}
Expand Down Expand Up @@ -641,15 +642,15 @@ func TestIsBlockReadyForProcessing_ValidBlock(t *testing.T) {

beaconState.Slot = params.BeaconConfig().GenesisSlot + 10

stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
t.Fatalf("Could not tree hash state: %v", err)
}
genesis := b.NewGenesisBlock([]byte{})
if err := chainService.beaconDB.SaveBlock(genesis); err != nil {
t.Fatalf("cannot save block: %v", err)
}
parentRoot, err := ssz.TreeHash(genesis)
parentRoot, err := hashutil.HashBeaconBlock(genesis)
if err != nil {
t.Fatalf("unable to get root of canonical head: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/chaintest/backend/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ go_library(
"//proto/beacon/p2p/v1:go_default_library",
"//shared/bls:go_default_library",
"//shared/forkutils:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/sliceutil:go_default_library",
"//shared/ssz:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
7 changes: 4 additions & 3 deletions beacon-chain/chaintest/backend/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"fmt"
"time"

"github.com/prysmaticlabs/prysm/shared/hashutil"

"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/forkutils"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/trieutil"
)

Expand All @@ -25,7 +26,7 @@ func generateSimulatedBlock(
simObjects *SimulatedObjects,
privKeys []*bls.SecretKey,
) (*pb.BeaconBlock, [32]byte, error) {
stateRoot, err := ssz.TreeHash(beaconState)
stateRoot, err := hashutil.HashProto(beaconState)
if err != nil {
return nil, [32]byte{}, fmt.Errorf("could not tree hash state: %v", err)
}
Expand Down Expand Up @@ -120,7 +121,7 @@ func generateSimulatedBlock(
ValidatorIndex: simObjects.simValidatorExit.ValidatorIndex,
})
}
blockRoot, err := ssz.TreeHash(block)
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {
return nil, [32]byte{}, fmt.Errorf("could not tree hash new block: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions beacon-chain/chaintest/backend/simulated_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"reflect"
"time"

"github.com/prysmaticlabs/prysm/shared/hashutil"

"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/prysm/beacon-chain/blockchain"
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
Expand All @@ -19,7 +21,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"github.com/prysmaticlabs/prysm/shared/ssz"
"github.com/prysmaticlabs/prysm/shared/trieutil"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -283,12 +284,12 @@ func (sb *SimulatedBackend) setupBeaconStateAndGenesisBlock(initialDeposits []*p
// We do not expect hashing initial beacon state and genesis block to
// fail, so we can safely ignore the error below.
// #nosec G104
stateRoot, err := ssz.TreeHash(sb.state)
stateRoot, err := hashutil.HashProto(sb.state)
if err != nil {
return fmt.Errorf("could not tree hash state: %v", err)
}
genesisBlock := b.NewGenesisBlock(stateRoot[:])
genesisBlockRoot, err := ssz.TreeHash(genesisBlock)
genesisBlockRoot, err := hashutil.HashBeaconBlock(genesisBlock)
if err != nil {
return fmt.Errorf("could not tree hash genesis block: %v", err)
}
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/core/blocks/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ go_library(
"//shared/forkutils:go_default_library",
"//shared/hashutil:go_default_library",
"//shared/params:go_default_library",
"//shared/ssz:go_default_library",
"//shared/trieutil:go_default_library",
"@com_github_ethereum_go_ethereum//common:go_default_library",
"@com_github_ethereum_go_ethereum//core/types:go_default_library",
Expand Down
3 changes: 1 addition & 2 deletions beacon-chain/core/blocks/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/ssz"
)

var clock utils.Clock = &utils.RealClock{}
Expand Down Expand Up @@ -89,7 +88,7 @@ func ProcessBlockRoots(state *pb.BeaconState, prevBlockRoot [32]byte) *pb.Beacon
// List[BeaconBlock] returns the child blocks of the given block.
func BlockChildren(block *pb.BeaconBlock, observedBlocks []*pb.BeaconBlock) ([]*pb.BeaconBlock, error) {
var children []*pb.BeaconBlock
root, err := ssz.TreeHash(block)
root, err := hashutil.HashBeaconBlock(block)
if err != nil {
return nil, fmt.Errorf("could not hash block: %v", err)
}
Expand Down
Loading