Clear Up Code Inconsistencies (#1836)

This commit is contained in:
Ivan Martinez 2019-03-03 12:31:29 -05:00 committed by terence tsao
parent fe2eb5a812
commit 5aa7320507
38 changed files with 56 additions and 115 deletions

View File

@ -7,11 +7,10 @@ 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/hashutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"

View File

@ -3,13 +3,12 @@ package blockchain
import (
"fmt"
"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/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
)
// LMDGhost applies the Latest Message Driven, Greediest Heaviest Observed Sub-Tree

View File

@ -6,14 +6,13 @@ 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/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -10,8 +10,6 @@ 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"
@ -26,6 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/forkutils"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared/trieutil"
@ -573,19 +572,19 @@ func TestUpdateHead_SavesBlock(t *testing.T) {
state *pb.BeaconState
logAssert string
}{
// Higher slot but same crystallized state should trigger chain update.
// Higher slot but same state should trigger chain update.
{
blockSlot: 64,
state: beaconState,
logAssert: "Chain head block and state updated",
},
// Higher slot, different crystallized state, but higher last finalized slot.
// Higher slot, different state, but higher last finalized slot.
{
blockSlot: 64,
state: &pb.BeaconState{FinalizedEpoch: 2},
logAssert: "Chain head block and state updated",
},
// Higher slot, different crystallized state, same last finalized slot,
// Higher slot, different state, same last finalized slot,
// but last justified slot.
{
blockSlot: 64,

View File

@ -6,12 +6,11 @@ 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/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
)

View File

@ -9,8 +9,6 @@ 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"
@ -19,6 +17,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/utils"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/sliceutil"
"github.com/prysmaticlabs/prysm/shared/trieutil"

View File

@ -4,7 +4,6 @@ import (
"testing"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -10,8 +10,6 @@ import (
"fmt"
"reflect"
"github.com/sirupsen/logrus"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state/stateutils"
@ -23,6 +21,7 @@ import (
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/trieutil"
"github.com/sirupsen/logrus"
)
// VerifyProposerSignature uses BLS signature verification to ensure

View File

@ -9,13 +9,12 @@ import (
"fmt"
"math"
"github.com/prysmaticlabs/prysm/shared/params"
block "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/validators"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
b "github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
// CurrentAttestations returns the pending attestations from current epoch.

View File

@ -8,11 +8,10 @@ import (
"strings"
"testing"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -105,7 +105,7 @@ func (db *BeaconDB) ChainHead() (*pb.BeaconBlock, error) {
}
// UpdateChainHead atomically updates the head of the chain as well as the corresponding state changes
// Including a new crystallized state is optional.
// Including a new state is optional.
func (db *BeaconDB) UpdateChainHead(block *pb.BeaconBlock, beaconState *pb.BeaconState) error {
blockRoot, err := hashutil.HashBeaconBlock(block)
if err != nil {

View File

@ -5,9 +5,8 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/shared/hashutil"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -6,10 +6,9 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/sirupsen/logrus"
"go.opencensus.io/trace"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
var (

View File

@ -1,13 +1,15 @@
package db
import "github.com/prysmaticlabs/prysm/shared/bytesutil"
import (
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
// The Schema will define how to store and retrieve data from the db.
// Currently we store blocks by prefixing `block` to their hash and
// using that as the key to store blocks.
// `block` + hash -> block
//
// We store the crystallized state using the crystallized state lookup key, and
// We store the state using the state lookup key, and
// also the genesis block using the genesis lookup key.
// The canonical head is stored using the canonical head lookup key.

View File

@ -96,41 +96,6 @@ func (db *BeaconDB) SaveState(beaconState *pb.BeaconState) error {
})
}
// UnfinalizedBlockState fetches an unfinalized block's
// active and crystallized state pair.
func (db *BeaconDB) UnfinalizedBlockState(stateRoot [32]byte) (*pb.BeaconState, error) {
var beaconState *pb.BeaconState
err := db.view(func(tx *bolt.Tx) error {
chainInfo := tx.Bucket(chainInfoBucket)
encState := chainInfo.Get(stateRoot[:])
if encState == nil {
return nil
}
var err error
beaconState, err = createState(encState)
return err
})
return beaconState, err
}
// SaveUnfinalizedBlockState persists the associated state
// for a given unfinalized block.
func (db *BeaconDB) SaveUnfinalizedBlockState(beaconState *pb.BeaconState) error {
enc, err := proto.Marshal(beaconState)
if err != nil {
return fmt.Errorf("unable to marshal the beacon state: %v", err)
}
stateHash := hashutil.Hash(enc)
return db.update(func(tx *bolt.Tx) error {
chainInfo := tx.Bucket(chainInfoBucket)
if err := chainInfo.Put(stateHash[:], enc); err != nil {
return fmt.Errorf("failed to save beacon state: %v", err)
}
return nil
})
}
func createState(enc []byte) (*pb.BeaconState, error) {
protoState := &pb.BeaconState{}
err := proto.Unmarshal(enc, protoState)

View File

@ -7,9 +7,8 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/gogo/protobuf/proto"
"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/params"

View File

@ -12,8 +12,6 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
@ -21,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum/core"
gethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"

View File

@ -5,13 +5,12 @@ import (
"strings"
"testing"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
"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/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -12,16 +12,14 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
ptypes "github.com/gogo/protobuf/types"
"github.com/golang/mock/gomock"
"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/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"

View File

@ -4,16 +4,14 @@ import (
"context"
"fmt"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
"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/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)
// ProposerServer defines a server implementation of the gRPC Proposer service,

View File

@ -6,9 +6,8 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
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/internal"
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"

View File

@ -7,10 +7,9 @@ import (
"io/ioutil"
"testing"
"github.com/prysmaticlabs/prysm/shared/params"
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/testutil"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"

View File

@ -4,12 +4,11 @@ import (
"context"
"fmt"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -17,13 +17,12 @@ import (
"sync"
"time"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/sirupsen/logrus"
@ -48,7 +47,7 @@ type Config struct {
// DefaultConfig provides the default configuration for a sync service.
// SyncPollingInterval determines how frequently the service checks that initial sync is complete.
// BlockBufferSize determines that buffer size of the `blockBuf` channel.
// CrystallizedStateBufferSize determines the buffer size of thhe `crystallizedStateBuf` channel.
// StateBufferSize determines the buffer size of thhe `stateBuf` channel.
func DefaultConfig() *Config {
return &Config{
SyncPollingInterval: time.Duration(params.BeaconConfig().SyncPollingInterval) * time.Second,

View File

@ -4,10 +4,9 @@ import (
"context"
"time"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/sirupsen/logrus"

View File

@ -7,10 +7,8 @@ import (
"time"
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
"github.com/prysmaticlabs/prysm/shared/event"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/testutil"
logTest "github.com/sirupsen/logrus/hooks/test"

View File

@ -7,14 +7,13 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/gogo/protobuf/proto"
"github.com/prysmaticlabs/prysm/beacon-chain/chaintest/backend"
"github.com/prysmaticlabs/prysm/beacon-chain/db"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/p2p"
"github.com/prysmaticlabs/prysm/shared/params"
)

View File

@ -23,8 +23,8 @@ GLOBAL OPTIONS:
{{range .App.Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}{{end}}{{if .FlagGroups}}
{{range .FlagGroups}}{{.Name}} OPTIONS:
{{range .Flags}}{{.}}
{{end}}
{{range .Flags}}{{.}}
{{end}}
{{end}}{{end}}{{if .App.Copyright }}
COPYRIGHT:
{{.App.Copyright}}

View File

@ -39,7 +39,7 @@ var (
Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.",
}
// GenesisJSON defines a flag for bootstrapping validators from genesis JSON.
// If this flag is not specified, beacon node will bootstrap validators from code from crystallized_state.go.
// If this flag is not specified, beacon node will bootstrap validators from code from state.go.
GenesisJSON = cli.StringFlag{
Name: "genesis-json",
Usage: "Beacon node will bootstrap genesis state defined in genesis.json",

View File

@ -5,9 +5,8 @@ import (
"crypto/rand"
"testing"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
)
func TestMarshalUnmarshal(t *testing.T) {

View File

@ -1,6 +1,8 @@
package keystore
import "golang.org/x/crypto/sha3"
import (
"golang.org/x/crypto/sha3"
)
// Keccak256 calculates and returns the Keccak256 hash of the input data.
func Keccak256(data ...[]byte) []byte {

View File

@ -7,10 +7,9 @@ import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/pborman/uuid"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

View File

@ -6,10 +6,9 @@ import (
"os"
"testing"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/pborman/uuid"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
)

View File

@ -1,6 +1,8 @@
package p2p
import "testing"
import (
"testing"
)
func TestBuildOptions(t *testing.T) {
opts := buildOptions(1)

View File

@ -1,6 +1,8 @@
package testutil
import "fmt"
import (
"fmt"
)
// CheckBit checks if a bit in a bit field is one.
func CheckBit(bitfield []byte, index int) (bool, error) {

View File

@ -1,6 +1,8 @@
package testutil
import "os"
import (
"os"
)
// TempDir returns a directory path for temporary test storage.
func TempDir() string {

View File

@ -8,13 +8,10 @@ import (
"testing"
"time"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/keystore"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/validator/accounts"
logTest "github.com/sirupsen/logrus/hooks/test"
)

View File

@ -7,7 +7,6 @@ import (
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/prysmaticlabs/prysm/validator/accounts"
"github.com/urfave/cli"
)