diff --git a/.travis.yml b/.travis.yml index 655194c38..f8f3ae8df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,10 @@ install: - (cd $HOME/gopath/src/github.com/harmony-one/bls; make BLS_SWAP_G=1 -j4) - go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26 - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1 + - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1 - make go-get + - go install golang.org/x/tools/cmd/goimports@latest + - go install github.com/harmony-ek/gencodec@latest - scripts/install_build_tools.sh script: - ${TEST} diff --git a/Makefile b/Makefile index dfcb7d63f..e7d6db4b4 100644 --- a/Makefile +++ b/Makefile @@ -151,3 +151,9 @@ rpmpub_dev: rpm rpmpub_prod: rpm ./scripts/package/publish-repo.sh -p prod -n rpm -s $(RPMBUILD) + +go-vet: + go vet ./... + +go-test: + go test ./... \ No newline at end of file diff --git a/accounts/keystore/watch.go b/accounts/keystore/watch.go index bbcfb9925..76c711452 100644 --- a/accounts/keystore/watch.go +++ b/accounts/keystore/watch.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build (darwin && !ios) || freebsd || (linux && !arm64) || netbsd || solaris // +build darwin,!ios freebsd linux,!arm64 netbsd solaris package keystore diff --git a/accounts/keystore/watch_fallback.go b/accounts/keystore/watch_fallback.go index 7c5e9cb2e..584a991f4 100644 --- a/accounts/keystore/watch_fallback.go +++ b/accounts/keystore/watch_fallback.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build ios || (linux && arm64) || windows || (!darwin && !freebsd && !linux && !netbsd && !solaris) // +build ios linux,arm64 windows !darwin,!freebsd,!linux,!netbsd,!solaris // This is the fallback implementation of directory watching. diff --git a/api/proto/message/gen.sh b/api/proto/message/gen.sh index c0ac17c89..5dc2fc1bc 100755 --- a/api/proto/message/gen.sh +++ b/api/proto/message/gen.sh @@ -1,2 +1 @@ -protoc -I ./ message.proto --go_out=plugins=grpc:./ -# protoc -I ./ message.proto --go_out=./ +protoc -I ./ message.proto --go_out=. --go-grpc_out=. diff --git a/api/proto/message/message.go b/api/proto/message/message.go index 0b6c22682..8ba69bcf6 100644 --- a/api/proto/message/message.go +++ b/api/proto/message/message.go @@ -1,3 +1,3 @@ package message -//go:generate protoc message.proto --go_out=plugins=grpc:. +//go:generate protoc message.proto --go_out=. --go-grpc_out=. diff --git a/api/proto/message/message.pb.go b/api/proto/message/message.pb.go index 5994a2179..dad905606 100644 --- a/api/proto/message/message.pb.go +++ b/api/proto/message/message.pb.go @@ -7,10 +7,6 @@ package message import ( - context "context" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" @@ -1296,83 +1292,3 @@ func file_message_proto_init() { file_message_proto_goTypes = nil file_message_proto_depIdxs = nil } - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion6 - -// ClientServiceClient is the client API for ClientService service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type ClientServiceClient interface { - Process(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) -} - -type clientServiceClient struct { - cc grpc.ClientConnInterface -} - -func NewClientServiceClient(cc grpc.ClientConnInterface) ClientServiceClient { - return &clientServiceClient{cc} -} - -func (c *clientServiceClient) Process(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) { - out := new(Response) - err := c.cc.Invoke(ctx, "/message.ClientService/Process", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// ClientServiceServer is the server API for ClientService service. -type ClientServiceServer interface { - Process(context.Context, *Message) (*Response, error) -} - -// UnimplementedClientServiceServer can be embedded to have forward compatible implementations. -type UnimplementedClientServiceServer struct { -} - -func (*UnimplementedClientServiceServer) Process(context.Context, *Message) (*Response, error) { - return nil, status.Errorf(codes.Unimplemented, "method Process not implemented") -} - -func RegisterClientServiceServer(s *grpc.Server, srv ClientServiceServer) { - s.RegisterService(&_ClientService_serviceDesc, srv) -} - -func _ClientService_Process_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(Message) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(ClientServiceServer).Process(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/message.ClientService/Process", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(ClientServiceServer).Process(ctx, req.(*Message)) - } - return interceptor(ctx, in, info, handler) -} - -var _ClientService_serviceDesc = grpc.ServiceDesc{ - ServiceName: "message.ClientService", - HandlerType: (*ClientServiceServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "Process", - Handler: _ClientService_Process_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "message.proto", -} diff --git a/api/proto/message/message_grpc.pb.go b/api/proto/message/message_grpc.pb.go new file mode 100644 index 000000000..e474fe072 --- /dev/null +++ b/api/proto/message/message_grpc.pb.go @@ -0,0 +1,101 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. + +package message + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// ClientServiceClient is the client API for ClientService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ClientServiceClient interface { + Process(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) +} + +type clientServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewClientServiceClient(cc grpc.ClientConnInterface) ClientServiceClient { + return &clientServiceClient{cc} +} + +func (c *clientServiceClient) Process(ctx context.Context, in *Message, opts ...grpc.CallOption) (*Response, error) { + out := new(Response) + err := c.cc.Invoke(ctx, "/message.ClientService/Process", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ClientServiceServer is the server API for ClientService service. +// All implementations must embed UnimplementedClientServiceServer +// for forward compatibility +type ClientServiceServer interface { + Process(context.Context, *Message) (*Response, error) + mustEmbedUnimplementedClientServiceServer() +} + +// UnimplementedClientServiceServer must be embedded to have forward compatible implementations. +type UnimplementedClientServiceServer struct { +} + +func (UnimplementedClientServiceServer) Process(context.Context, *Message) (*Response, error) { + return nil, status.Errorf(codes.Unimplemented, "method Process not implemented") +} +func (UnimplementedClientServiceServer) mustEmbedUnimplementedClientServiceServer() {} + +// UnsafeClientServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ClientServiceServer will +// result in compilation errors. +type UnsafeClientServiceServer interface { + mustEmbedUnimplementedClientServiceServer() +} + +func RegisterClientServiceServer(s grpc.ServiceRegistrar, srv ClientServiceServer) { + s.RegisterService(&ClientService_ServiceDesc, srv) +} + +func _ClientService_Process_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Message) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ClientServiceServer).Process(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/message.ClientService/Process", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ClientServiceServer).Process(ctx, req.(*Message)) + } + return interceptor(ctx, in, info, handler) +} + +// ClientService_ServiceDesc is the grpc.ServiceDesc for ClientService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ClientService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "message.ClientService", + HandlerType: (*ClientServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Process", + Handler: _ClientService_Process_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "message.proto", +} diff --git a/api/proto/message/server.go b/api/proto/message/server.go index e42a9b393..695bf907f 100644 --- a/api/proto/message/server.go +++ b/api/proto/message/server.go @@ -18,6 +18,7 @@ const ( // Server is the Server struct for client service package. type Server struct { + UnimplementedClientServiceServer server *grpc.Server CreateTransactionForEnterMethod func(int64, string) error GetResult func(string) ([]string, []*big.Int) diff --git a/block/factory/factory.go b/block/factory/factory.go index 896a4fc28..1601c291a 100644 --- a/block/factory/factory.go +++ b/block/factory/factory.go @@ -40,7 +40,7 @@ func (f *factory) NewHeader(epoch *big.Int) *block.Header { impl = v0.NewHeader() } impl.SetEpoch(epoch) - return &block.Header{impl} + return &block.Header{Header: impl} } // Factories corresponding to well-known chain configurations. diff --git a/block/v3/header.go b/block/v3/header.go index f65546efb..ea62204a9 100644 --- a/block/v3/header.go +++ b/block/v3/header.go @@ -70,7 +70,7 @@ type headerFields struct { Vdf []byte `json:"vdf"` ShardState []byte `json:"shardState"` CrossLinks []byte `json:"crossLink"` - Slashes []byte `json:slashes` + Slashes []byte `json:"slashes"` } // ParentHash is the header hash of the parent block. For the genesis block diff --git a/cmd/harmony/config.go b/cmd/harmony/config.go index 3728c6501..7299a74a9 100644 --- a/cmd/harmony/config.go +++ b/cmd/harmony/config.go @@ -194,7 +194,6 @@ var dumpConfigLegacyCmd = &cobra.Command{ func registerDumpConfigFlags() error { return cli.RegisterFlags(dumpConfigCmd, []cli.Flag{networkTypeFlag}) - return cli.RegisterFlags(dumpConfigLegacyCmd, []cli.Flag{networkTypeFlag}) } func promptConfigUpdate() bool { diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 9ca1219e2..9aa62ca1d 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -840,7 +840,7 @@ func setupBlacklist(hc harmonyconfig.HarmonyConfig) (map[ethCommon.Address]struc func listenOSSigAndShutDown(node *node.Node) { // Prepare for graceful shutdown from os signals - osSignal := make(chan os.Signal) + osSignal := make(chan os.Signal, 1) signal.Notify(osSignal, syscall.SIGINT, syscall.SIGTERM) sig := <-osSignal utils.Logger().Warn().Str("signal", sig.String()).Msg("Gracefully shutting down...") diff --git a/common/fdlimit/fdlimit_unix.go b/common/fdlimit/fdlimit_unix.go index e5a575f7a..a1f388ebb 100644 --- a/common/fdlimit/fdlimit_unix.go +++ b/common/fdlimit/fdlimit_unix.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build linux || netbsd || openbsd || solaris // +build linux netbsd openbsd solaris package fdlimit diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 2919ea218..fc9cd56bf 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -424,7 +424,6 @@ func (consensus *Consensus) Start( return } } - consensus.getLogger().Info().Msg("[ConsensusMainLoop] Ended.") }() if consensus.dHelper != nil { diff --git a/consensus/construct_test.go b/consensus/construct_test.go index dd833095a..69c8e89b2 100644 --- a/consensus/construct_test.go +++ b/consensus/construct_test.go @@ -39,7 +39,7 @@ func TestConstructAnnounceMessage(test *testing.T) { consensus.blockHash = [32]byte{} pubKeyWrapper := bls.PublicKeyWrapper{Object: blsPriKey.GetPublicKey()} pubKeyWrapper.Bytes.FromLibBLSPublicKey(pubKeyWrapper.Object) - priKeyWrapper := bls.PrivateKeyWrapper{blsPriKey, &pubKeyWrapper} + priKeyWrapper := bls.PrivateKeyWrapper{Pri: blsPriKey, Pub: &pubKeyWrapper} if _, err = consensus.construct(msg_pb.MessageType_ANNOUNCE, nil, []*bls.PrivateKeyWrapper{&priKeyWrapper}); err != nil { test.Fatalf("could not construct announce: %v", err) } @@ -110,7 +110,7 @@ func TestConstructPreparedMessage(test *testing.T) { pubKeyWrapper := bls.PublicKeyWrapper{Object: blsPriKey.GetPublicKey()} pubKeyWrapper.Bytes.FromLibBLSPublicKey(pubKeyWrapper.Object) - priKeyWrapper := bls.PrivateKeyWrapper{blsPriKey, &pubKeyWrapper} + priKeyWrapper := bls.PrivateKeyWrapper{Pri: blsPriKey, Pub: &pubKeyWrapper} network, err := consensus.construct(msg_pb.MessageType_PREPARED, nil, []*bls.PrivateKeyWrapper{&priKeyWrapper}) if err != nil { test.Errorf("Error when creating prepared message") @@ -134,12 +134,12 @@ func TestConstructPrepareMessage(test *testing.T) { blsPriKey1 := bls.RandPrivateKey() pubKeyWrapper1 := bls.PublicKeyWrapper{Object: blsPriKey1.GetPublicKey()} pubKeyWrapper1.Bytes.FromLibBLSPublicKey(pubKeyWrapper1.Object) - priKeyWrapper1 := bls.PrivateKeyWrapper{blsPriKey1, &pubKeyWrapper1} + priKeyWrapper1 := bls.PrivateKeyWrapper{Pri: blsPriKey1, Pub: &pubKeyWrapper1} blsPriKey2 := bls.RandPrivateKey() pubKeyWrapper2 := bls.PublicKeyWrapper{Object: blsPriKey2.GetPublicKey()} pubKeyWrapper2.Bytes.FromLibBLSPublicKey(pubKeyWrapper2.Object) - priKeyWrapper2 := bls.PrivateKeyWrapper{blsPriKey2, &pubKeyWrapper2} + priKeyWrapper2 := bls.PrivateKeyWrapper{Pri: blsPriKey2, Pub: &pubKeyWrapper2} decider := quorum.NewDecider( quorum.SuperMajorityStake, shard.BeaconChainShardID, @@ -226,12 +226,12 @@ func TestConstructCommitMessage(test *testing.T) { blsPriKey1 := bls.RandPrivateKey() pubKeyWrapper1 := bls.PublicKeyWrapper{Object: blsPriKey1.GetPublicKey()} pubKeyWrapper1.Bytes.FromLibBLSPublicKey(pubKeyWrapper1.Object) - priKeyWrapper1 := bls.PrivateKeyWrapper{blsPriKey1, &pubKeyWrapper1} + priKeyWrapper1 := bls.PrivateKeyWrapper{Pri: blsPriKey1, Pub: &pubKeyWrapper1} blsPriKey2 := bls.RandPrivateKey() pubKeyWrapper2 := bls.PublicKeyWrapper{Object: blsPriKey2.GetPublicKey()} pubKeyWrapper2.Bytes.FromLibBLSPublicKey(pubKeyWrapper2.Object) - priKeyWrapper2 := bls.PrivateKeyWrapper{blsPriKey2, &pubKeyWrapper2} + priKeyWrapper2 := bls.PrivateKeyWrapper{Pri: blsPriKey2, Pub: &pubKeyWrapper2} decider := quorum.NewDecider( quorum.SuperMajorityStake, shard.BeaconChainShardID, diff --git a/consensus/double_sign.go b/consensus/double_sign.go index 86dfd050e..a899961ca 100644 --- a/consensus/double_sign.go +++ b/consensus/double_sign.go @@ -86,14 +86,14 @@ func (consensus *Consensus) checkDoubleSign(recvMsg *FBFTMessage) bool { evid := slash.Evidence{ ConflictingVotes: slash.ConflictingVotes{ FirstVote: slash.Vote{ - alreadyCastBallot.SignerPubKeys, - alreadyCastBallot.BlockHeaderHash, - alreadyCastBallot.Signature, + SignerPubKeys: alreadyCastBallot.SignerPubKeys, + BlockHeaderHash: alreadyCastBallot.BlockHeaderHash, + Signature: alreadyCastBallot.Signature, }, SecondVote: slash.Vote{ - secondKeys, - recvMsg.BlockHash, - common.Hex2Bytes(doubleSign.SerializeToHexStr()), + SignerPubKeys: secondKeys, + BlockHeaderHash: recvMsg.BlockHash, + Signature: common.Hex2Bytes(doubleSign.SerializeToHexStr()), }}, Moment: slash.Moment{ Epoch: curHeader.Epoch(), diff --git a/consensus/quorum/one-node-staked-vote_test.go b/consensus/quorum/one-node-staked-vote_test.go index 3529ccaa0..f18a5ae06 100644 --- a/consensus/quorum/one-node-staked-vote_test.go +++ b/consensus/quorum/one-node-staked-vote_test.go @@ -45,7 +45,7 @@ func generateRandomSlot() (shard.Slot, bls_core.SecretKey) { key := bls.SerializedPublicKey{} key.FromLibBLSPublicKey(secretKey.GetPublicKey()) stake := numeric.NewDecFromBigInt(big.NewInt(int64(stakeGen.Int63n(maxStakeGen)))) - return shard.Slot{addr, key, &stake}, secretKey + return shard.Slot{EcdsaAddress: addr, BLSPublicKey: key, EffectiveStake: &stake}, secretKey } // 50 Harmony Nodes, 50 Staked Nodes @@ -73,7 +73,7 @@ func setupBaseCase() (Decider, *TallyResult, shard.SlotList, map[string]secretKe decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID) decider.UpdateParticipants(pubKeys) tally, err := decider.SetVoters(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) if err != nil { panic("Unable to SetVoters for Base Case") @@ -102,7 +102,7 @@ func setupEdgeCase() (Decider, *TallyResult, shard.SlotList, secretKeyMap) { decider := NewDecider(SuperMajorityStake, shard.BeaconChainShardID) decider.UpdateParticipants(pubKeys) tally, err := decider.SetVoters(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) if err != nil { panic("Unable to SetVoters for Edge Case") diff --git a/consensus/quorum/quorom_test.go b/consensus/quorum/quorom_test.go index 73767ea25..53631b575 100644 --- a/consensus/quorum/quorom_test.go +++ b/consensus/quorum/quorom_test.go @@ -223,7 +223,7 @@ func TestAddNewVote(test *testing.T) { decider.UpdateParticipants(pubKeys) decider.SetVoters(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) aggSig := &bls_core.Sign{} @@ -328,7 +328,7 @@ func TestAddNewVoteAggregateSig(test *testing.T) { decider.UpdateParticipants(pubKeys) decider.SetVoters(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) aggSig := &bls_core.Sign{} @@ -412,7 +412,7 @@ func TestAddNewVoteInvalidAggregateSig(test *testing.T) { decider.UpdateParticipants(pubKeys) decider.SetVoters(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) aggSig := &bls_core.Sign{} diff --git a/consensus/votepower/roster_test.go b/consensus/votepower/roster_test.go index 26d13564b..2b669353f 100644 --- a/consensus/votepower/roster_test.go +++ b/consensus/votepower/roster_test.go @@ -52,7 +52,7 @@ func generateRandomSlot() shard.Slot { key := bls.SerializedPublicKey{} key.FromLibBLSPublicKey(secretKey.GetPublicKey()) stake := numeric.NewDecFromBigInt(big.NewInt(int64(stakeGen.Int63n(maxStakeGen)))) - return shard.Slot{addr, key, &stake} + return shard.Slot{EcdsaAddress: addr, BLSPublicKey: key, EffectiveStake: &stake} } func TestCompute(t *testing.T) { @@ -100,7 +100,7 @@ func TestCompute(t *testing.T) { expectedRoster.TheirVotingPowerTotalPercentage = theirPercentage computedRoster, err := Compute(&shard.Committee{ - shard.BeaconChainShardID, slotList, + ShardID: shard.BeaconChainShardID, Slots: slotList, }, big.NewInt(3)) if err != nil { t.Error("Computed Roster failed on vote summation to one") diff --git a/core/blockchain.go b/core/blockchain.go index 2dd5a09d8..f40a5b61a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2590,7 +2590,7 @@ func (bc *BlockChain) ComputeAndUpdateAPR( } } else { // only insert if APR for current epoch does not exists - aprEntry := staking.APREntry{now, *aprComputed} + aprEntry := staking.APREntry{Epoch: now, Value: *aprComputed} l := len(stats.APRs) // first time inserting apr for validator or // apr for current epoch does not exists @@ -2628,7 +2628,7 @@ func (bc *BlockChain) UpdateValidatorSnapshots( return err } - snapshot := &staking.ValidatorSnapshot{validator, epoch} + snapshot := &staking.ValidatorSnapshot{Validator: validator, Epoch: epoch} if err := bc.WriteValidatorSnapshot(batch, snapshot); err != nil { return err } @@ -2775,13 +2775,13 @@ func (bc *BlockChain) UpdateStakingMetaData( return newValidators, err } - if err := bc.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{validator, epoch}); err != nil { + if err := bc.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{Validator: validator, Epoch: epoch}); err != nil { return newValidators, err } // For validator created at exactly the last block of an epoch, we should create the snapshot // for next epoch too. if newEpoch.Cmp(epoch) > 0 { - if err := bc.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{validator, newEpoch}); err != nil { + if err := bc.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{Validator: validator, Epoch: newEpoch}); err != nil { return newValidators, err } } @@ -2854,9 +2854,9 @@ func (bc *BlockChain) prepareStakingMetaData( // Add self delegation into the index selfIndex := staking.DelegationIndex{ - createValidator.ValidatorAddress, - uint64(0), - blockNum, + ValidatorAddress: createValidator.ValidatorAddress, + Index: uint64(0), + BlockNum: blockNum, } delegations, ok := newDelegations[createValidator.ValidatorAddress] if !ok { @@ -2974,9 +2974,9 @@ func (bc *BlockChain) addDelegationIndex( ) { // TODO(audit): change the way of indexing if we allow delegation deletion. delegations = append(delegations, staking.DelegationIndex{ - validatorAddress, - uint64(i), - blockNum, + ValidatorAddress: validatorAddress, + Index: uint64(i), + BlockNum: blockNum, }) } } diff --git a/core/evm_test.go b/core/evm_test.go index 58510d155..df532871b 100644 --- a/core/evm_test.go +++ b/core/evm_test.go @@ -77,12 +77,12 @@ func TestEVMStaking(t *testing.T) { // write it to snapshot so that we can use it in edit // use a copy because we are editing below (wrapper.Delegations) wrapper, err := db.ValidatorWrapper(createValidator.ValidatorAddress, false, true) - err = chain.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{wrapper, header.Epoch()}) + err = chain.WriteValidatorSnapshot(batch, &staking.ValidatorSnapshot{Validator: wrapper, Epoch: header.Epoch()}) // also write the delegation so we can use it in CollectRewards selfIndex := staking.DelegationIndex{ - createValidator.ValidatorAddress, - uint64(0), - common.Big0, // block number at which delegation starts + ValidatorAddress: createValidator.ValidatorAddress, + Index: uint64(0), + BlockNum: common.Big0, // block number at which delegation starts } err = chain.writeDelegationsByDelegator(batch, createValidator.ValidatorAddress, []staking.DelegationIndex{selfIndex}) @@ -98,10 +98,9 @@ func TestEVMStaking(t *testing.T) { delegate := sampleDelegate(*key) // add undelegations in epoch0 wrapper.Delegations[0].Undelegations = []staking.Undelegation{ - staking.Undelegation{ - new(big.Int).Mul(big.NewInt(denominations.One), - big.NewInt(10000)), - common.Big0, + { + Amount: new(big.Int).Mul(big.NewInt(denominations.One), big.NewInt(10000)), + Epoch: common.Big0, }, } // redelegate using epoch1, so that we can cover the locked tokens use case as well diff --git a/core/gen_genesis.go b/core/gen_genesis.go index bc961f656..aea695176 100644 --- a/core/gen_genesis.go +++ b/core/gen_genesis.go @@ -5,6 +5,7 @@ package core import ( "encoding/json" "errors" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" diff --git a/core/rawdb/accessors_offchain.go b/core/rawdb/accessors_offchain.go index 3ce397eac..c95cf73f5 100644 --- a/core/rawdb/accessors_offchain.go +++ b/core/rawdb/accessors_offchain.go @@ -159,7 +159,7 @@ func ReadValidatorSnapshot( Msg("Unable to decode validator snapshot from database") return nil, err } - s := staking.ValidatorSnapshot{&v, epoch} + s := staking.ValidatorSnapshot{Validator: &v, Epoch: epoch} return &s, nil } diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index c09c304d2..cf2173e19 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -926,7 +926,7 @@ func makeValidValidatorWrapper(addr common.Address) stk.ValidatorWrapper { MaxRate: numeric.ZeroDec(), MaxChangeRate: numeric.ZeroDec(), } - c := stk.Commission{cr, big.NewInt(300)} + c := stk.Commission{CommissionRates: cr, UpdateHeight: big.NewInt(300)} d := stk.Description{ Name: "Wayne", Identity: "wen", diff --git a/core/state_processor.go b/core/state_processor.go index 4fd6dade0..e1db9ed73 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -299,7 +299,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo var cxReceipt *types.CXReceipt // Do not create cxReceipt if EVM call failed if txType == types.SubtractionOnly && !failedExe { - cxReceipt = &types.CXReceipt{tx.Hash(), msg.From(), msg.To(), tx.ShardID(), tx.ToShardID(), msg.Value()} + cxReceipt = &types.CXReceipt{TxHash: tx.Hash(), From: msg.From(), To: msg.To(), ShardID: tx.ShardID(), ToShardID: tx.ToShardID(), Amount: msg.Value()} } else { cxReceipt = nil } diff --git a/core/types/block_test.go b/core/types/block_test.go index d5f1081ea..4cd31369f 100644 --- a/core/types/block_test.go +++ b/core/types/block_test.go @@ -927,7 +927,7 @@ func TestBlock_EncodeRLP(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - b := &Block{header: &block.Header{tt.header}} + b := &Block{header: &block.Header{Header: tt.header}} w := &bytes.Buffer{} err := b.EncodeRLP(w) if (err != nil) != tt.wantErr { diff --git a/core/vm/int_pool_verifier.go b/core/vm/int_pool_verifier.go index 82fbfed69..c2382b189 100644 --- a/core/vm/int_pool_verifier.go +++ b/core/vm/int_pool_verifier.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build VERIFY_EVM_INTEGER_POOL // +build VERIFY_EVM_INTEGER_POOL package vm diff --git a/core/vm/int_pool_verifier_empty.go b/core/vm/int_pool_verifier_empty.go index a5f1dc02b..6f7ff5759 100644 --- a/core/vm/int_pool_verifier_empty.go +++ b/core/vm/int_pool_verifier_empty.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build !VERIFY_EVM_INTEGER_POOL // +build !VERIFY_EVM_INTEGER_POOL package vm diff --git a/core/vm/runtime/fuzz.go b/core/vm/runtime/fuzz.go index cb9ff08b5..d20a784e1 100644 --- a/core/vm/runtime/fuzz.go +++ b/core/vm/runtime/fuzz.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build gofuzz // +build gofuzz package runtime diff --git a/eth/rpc/constants_unix.go b/eth/rpc/constants_unix.go index 860e37d65..1a2433a18 100644 --- a/eth/rpc/constants_unix.go +++ b/eth/rpc/constants_unix.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris package rpc diff --git a/eth/rpc/constants_unix_nocgo.go b/eth/rpc/constants_unix_nocgo.go index ecb231f92..a62e4ee52 100644 --- a/eth/rpc/constants_unix_nocgo.go +++ b/eth/rpc/constants_unix_nocgo.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build !cgo && !windows // +build !cgo,!windows package rpc diff --git a/eth/rpc/ipc_js.go b/eth/rpc/ipc_js.go index 7e7554a76..453a20bc1 100644 --- a/eth/rpc/ipc_js.go +++ b/eth/rpc/ipc_js.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build js // +build js package rpc diff --git a/eth/rpc/ipc_unix.go b/eth/rpc/ipc_unix.go index f4690cc0a..249a9cf04 100644 --- a/eth/rpc/ipc_unix.go +++ b/eth/rpc/ipc_unix.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris package rpc diff --git a/eth/rpc/ipc_windows.go b/eth/rpc/ipc_windows.go index ca56a3ce4..adb1826f0 100644 --- a/eth/rpc/ipc_windows.go +++ b/eth/rpc/ipc_windows.go @@ -14,6 +14,7 @@ // You should have received a copy of the GNU Lesser General Public License // along with the go-ethereum library. If not, see . +//go:build windows // +build windows package rpc diff --git a/go.mod b/go.mod index 934f0234c..df4e40c37 100644 --- a/go.mod +++ b/go.mod @@ -16,13 +16,11 @@ require ( github.com/deckarep/golang-set v1.7.1 github.com/ethereum/go-ethereum v1.9.25 github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a // indirect - github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c // indirect github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.2 github.com/golangci/golangci-lint v1.22.2 github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 - github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846 github.com/harmony-one/abool v1.0.1 github.com/harmony-one/bls v0.0.6 github.com/harmony-one/taggedrlp v0.1.4 @@ -53,14 +51,14 @@ require ( github.com/spf13/viper v1.6.1 github.com/stretchr/testify v1.7.0 github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca - github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect + github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee go.uber.org/ratelimit v0.1.0 go.uber.org/zap v1.16.0 golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf - golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 + golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba - golang.org/x/tools v0.1.7 + golang.org/x/tools v0.1.7 // indirect google.golang.org/grpc v1.33.2 google.golang.org/protobuf v1.26.0 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c diff --git a/go.sum b/go.sum index 66a55c970..56e29ce92 100644 --- a/go.sum +++ b/go.sum @@ -209,8 +209,6 @@ github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= -github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c h1:uYNKzPntb8c6DKvP9EfrBjkLkU7pM4lM+uuHSIa8UtU= -github.com/garslo/gogen v0.0.0-20170307003452-d6ebae628c7c/go.mod h1:Q0X6pkwTILDlzrGEckF6HKjXe48EgsY/l7K7vhY4MW8= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI= github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -389,8 +387,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU= github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= -github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846 h1:mYQ5htv2sj7m/mwlonteCTD80ODMlPUQTwbKJk+hi3Q= -github.com/harmony-ek/gencodec v0.0.0-20190215044613-e6740dbdd846/go.mod h1:YZcPnufUw70msUSudLvxcQOSpnZJgaMS9WIU8IGEtBg= github.com/harmony-one/abool v1.0.1 h1:SjXLmrr3W8h6lY37gRuWtLiRknUOchnUnsXJWK6Gbm4= github.com/harmony-one/abool v1.0.1/go.mod h1:9sq0PJzb1SqRpKrpEV4Ttvm9WV5uud8sfrsPw3AIBJA= github.com/harmony-one/bls v0.0.6 h1:KG4q4JwdkPf3DtFvJmAgMRWT6QdY1A/wqN/Qt+S4VaQ= @@ -553,7 +549,6 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ= diff --git a/hmy/downloader/longrange_test.go b/hmy/downloader/longrange_test.go index 975ad2c22..105aaf064 100644 --- a/hmy/downloader/longrange_test.go +++ b/hmy/downloader/longrange_test.go @@ -123,7 +123,7 @@ func TestLrSyncIter_FetchAndInsertBlocks(t *testing.T) { targetBN := uint64(1000) chain := newTestBlockChain(0, nil) protocol := newTestSyncProtocol(targetBN, 32, nil) - ctx, _ := context.WithCancel(context.Background()) + ctx := context.Background() lsi := &lrSyncIter{ bc: chain, @@ -155,7 +155,7 @@ func TestLrSyncIter_FetchAndInsertBlocks_ErrRequest(t *testing.T) { } chain := newTestBlockChain(0, nil) protocol := newTestSyncProtocol(targetBN, 32, errHook) - ctx, _ := context.WithCancel(context.Background()) + ctx := context.Background() lsi := &lrSyncIter{ bc: chain, @@ -187,7 +187,7 @@ func TestLrSyncIter_FetchAndInsertBlocks_ErrInsert(t *testing.T) { } chain := newTestBlockChain(0, errHook) protocol := newTestSyncProtocol(targetBN, 32, nil) - ctx, _ := context.WithCancel(context.Background()) + ctx := context.Background() lsi := &lrSyncIter{ bc: chain, @@ -219,7 +219,7 @@ func TestLrSyncIter_FetchAndInsertBlocks_RandomErr(t *testing.T) { } chain := newTestBlockChain(0, errHook) protocol := newTestSyncProtocol(targetBN, 32, errHook) - ctx, _ := context.WithCancel(context.Background()) + ctx := context.Background() lsi := &lrSyncIter{ bc: chain, diff --git a/hmy/downloader/shortrange.go b/hmy/downloader/shortrange.go index 3fdb2ec7b..19df038e7 100644 --- a/hmy/downloader/shortrange.go +++ b/hmy/downloader/shortrange.go @@ -122,6 +122,7 @@ func (sh *srHelper) getHashChain(curBN uint64) ([]common.Hash, []sttypes.StreamI func (sh *srHelper) getBlocksByHashes(hashes []common.Hash, whitelist []sttypes.StreamID) ([]*types.Block, []sttypes.StreamID, error) { ctx, cancel := context.WithCancel(sh.ctx) + defer cancel() m := newGetBlocksByHashManager(hashes, whitelist) var ( diff --git a/hmy/transaction.go b/hmy/transaction.go index eadfe2ea2..3b0b8c972 100644 --- a/hmy/transaction.go +++ b/hmy/transaction.go @@ -44,7 +44,7 @@ func (hmy *Harmony) ResendCx(ctx context.Context, txID common.Hash) (uint64, boo if tx.ShardID() == tx.ToShardID() || blk.Header().ShardID() != tx.ShardID() { return 0, false } - entry := core.CxEntry{blockHash, tx.ToShardID()} + entry := core.CxEntry{BlockHash: blockHash, ToShardID: tx.ToShardID()} success := hmy.CxPool.Add(entry) return blockNum, success } diff --git a/internal/chain/reward.go b/internal/chain/reward.go index 44295ce00..786cb91cb 100644 --- a/internal/chain/reward.go +++ b/internal/chain/reward.go @@ -498,7 +498,7 @@ func distributeRewardBeforeAggregateEpoch(bc engine.ChainReader, state *state.DB if err != nil { return network.EmptyPayout, errors.Wrapf(err, "shard 0 block %d reward error with bitmap %x", header.Number(), header.LastCommitBitmap()) } - subComm := shard.Committee{shard.BeaconChainShardID, members} + subComm := shard.Committee{ShardID: shard.BeaconChainShardID, Slots: members} if err := availability.IncrementValidatorSigningCounts( beaconChain, diff --git a/node/node.go b/node/node.go index 4b6b78446..a5410cec7 100644 --- a/node/node.go +++ b/node/node.go @@ -649,7 +649,7 @@ func (node *Node) StartPubSub() error { } allTopics = append( allTopics, u{ - NamedTopic: p2p.NamedTopic{string(key), topicHandle}, + NamedTopic: p2p.NamedTopic{Name: string(key), Topic: topicHandle}, consensusBound: isCon, }, ) @@ -787,19 +787,6 @@ func (node *Node) StartPubSub() error { nodeP2PMessageCounterVec.With(prometheus.Labels{"type": "ignored"}).Inc() return libp2p_pubsub.ValidationReject } - select { - case <-ctx.Done(): - if errors.Is(ctx.Err(), context.DeadlineExceeded) || - errors.Is(ctx.Err(), context.Canceled) { - utils.Logger().Warn(). - Str("topic", topicNamed).Msg("[context] exceeded validation deadline") - } - errChan <- withError{errors.WithStack(ctx.Err()), nil} - default: - return libp2p_pubsub.ValidationAccept - } - - return libp2p_pubsub.ValidationReject }, // WithValidatorTimeout is an option that sets a timeout for an (asynchronous) topic validator. By default there is no timeout in asynchronous validators. // TODO: Currently this timeout is useless. Verify me. diff --git a/node/node_genesis.go b/node/node_genesis.go index ba9df65d7..fbc761b53 100644 --- a/node/node_genesis.go +++ b/node/node_genesis.go @@ -30,7 +30,7 @@ func (gi *genesisInitializer) InitChainDB(db ethdb.Database, shardID uint32) err if err != nil { return errors.New("cannot find local shard in genesis") } - shardState = &shard.State{nil, []shard.Committee{*subComm}} + shardState = &shard.State{Shards: []shard.Committee{*subComm}} } gi.node.SetupGenesisBlock(db, shardID, shardState) return nil diff --git a/node/node_handler_test.go b/node/node_handler_test.go index 84d034e0b..535087d07 100644 --- a/node/node_handler_test.go +++ b/node/node_handler_test.go @@ -155,15 +155,14 @@ func TestVerifyVRF(t *testing.T) { spKey := bls.SerializedPublicKey{} spKey.FromLibBLSPublicKey(pubKey) curNodeID := shard.Slot{ - ecdsaAddr, - spKey, - nil, + EcdsaAddress: ecdsaAddr, + BLSPublicKey: spKey, } com.Slots = append(com.Slots, curNodeID) shardState.Epoch = big.NewInt(1) shardState.Shards = append(shardState.Shards, com) - node.Consensus.LeaderPubKey = &bls.PublicKeyWrapper{spKey, pubKey} + node.Consensus.LeaderPubKey = &bls.PublicKeyWrapper{Bytes: spKey, Object: pubKey} node.Worker.GetCurrentHeader().SetEpoch(big.NewInt(1)) node.Consensus.GenerateVrfAndProof(node.Worker.GetCurrentHeader()) block, _ := node.Worker.FinalizeNewBlock( diff --git a/p2p/discovery/discovery.go b/p2p/discovery/discovery.go index 8456f9423..cf5184368 100644 --- a/p2p/discovery/discovery.go +++ b/p2p/discovery/discovery.go @@ -45,6 +45,7 @@ func NewDHTDiscovery(host libp2p_host.Host, opt DHTConfig) (Discovery, error) { ctx, cancel := context.WithCancel(context.Background()) dht, err := libp2p_dht.New(ctx, host, opts...) if err != nil { + cancel() return nil, err } d := libp2p_dis.NewRoutingDiscovery(dht) diff --git a/p2p/host.go b/p2p/host.go index c0d765a9a..6895978c7 100644 --- a/p2p/host.go +++ b/p2p/host.go @@ -109,6 +109,7 @@ func NewHost(cfg HostConfig) (Host, error) { libp2p.BandwidthReporter(newCounter()), ) if err != nil { + cancel() return nil, errors.Wrapf(err, "cannot initialize libp2p host") } @@ -118,6 +119,7 @@ func NewHost(cfg HostConfig) (Host, error) { DiscConcurrency: cfg.DiscConcurrency, }) if err != nil { + cancel() return nil, errors.Wrap(err, "cannot create DHT discovery") } @@ -169,6 +171,7 @@ func NewHost(cfg HostConfig) (Host, error) { pubsub, err := libp2p_pubsub.NewGossipSub(ctx, p2pHost, options...) if err != nil { + cancel() return nil, errors.Wrapf(err, "cannot initialize libp2p pub-sub") } diff --git a/p2p/stream/common/requestmanager/requestmanager_test.go b/p2p/stream/common/requestmanager/requestmanager_test.go index 63804d0d5..1d6b6e841 100644 --- a/p2p/stream/common/requestmanager/requestmanager_test.go +++ b/p2p/stream/common/requestmanager/requestmanager_test.go @@ -25,7 +25,8 @@ func TestRequestManager_Request_Normal(t *testing.T) { defer ts.Close() req := makeTestRequest(100) - ctx, _ := context.WithTimeout(context.Background(), 1*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() res := <-ts.rm.doRequestAsync(ctx, req) if res.err != nil { @@ -92,7 +93,8 @@ func TestRequestManager_RemoveStream(t *testing.T) { defer ts.Close() req := makeTestRequest(100) - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() resC := ts.rm.doRequestAsync(ctx, req) time.Sleep(defTestSleep) @@ -153,7 +155,8 @@ func TestRequestManager_StaleDelivery(t *testing.T) { defer ts.Close() req := makeTestRequest(100) - ctx, _ := context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + defer cancel() resC := ts.rm.doRequestAsync(ctx, req) time.Sleep(2 * time.Second) @@ -192,7 +195,8 @@ func TestRequestManager_cancelWaitings(t *testing.T) { ts.Start() defer ts.Close() - ctx1, _ := context.WithTimeout(context.Background(), 1*time.Second) + ctx1, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() ctx2, cancel2 := context.WithTimeout(context.Background(), 1*time.Second) resC1 := ts.rm.doRequestAsync(ctx1, req1) resC2 := ts.rm.doRequestAsync(ctx2, req2) @@ -245,7 +249,8 @@ func TestRequestManager_Close(t *testing.T) { ts := newTestSuite(delayF, respF, 3) ts.Start() - ctx, _ := context.WithTimeout(context.Background(), 2*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() resC := ts.rm.doRequestAsync(ctx, makeTestRequest(0)) time.Sleep(100 * time.Millisecond) ts.Close() @@ -266,7 +271,8 @@ func TestRequestManager_Request_Blacklist(t *testing.T) { defer ts.Close() req := makeTestRequest(100) - ctx, _ := context.WithTimeout(context.Background(), 1*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() res := <-ts.rm.doRequestAsync(ctx, req, WithBlacklist([]sttypes.StreamID{ makeStreamID(0), makeStreamID(1), @@ -293,7 +299,8 @@ func TestRequestManager_Request_Whitelist(t *testing.T) { defer ts.Close() req := makeTestRequest(100) - ctx, _ := context.WithTimeout(context.Background(), 1*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + defer cancel() res := <-ts.rm.doRequestAsync(ctx, req, WithWhitelist([]sttypes.StreamID{ makeStreamID(3), })) diff --git a/p2p/stream/common/streammanager/streammanager.go b/p2p/stream/common/streammanager/streammanager.go index c040d7d34..743f1c87c 100644 --- a/p2p/stream/common/streammanager/streammanager.go +++ b/p2p/stream/common/streammanager/streammanager.go @@ -332,8 +332,12 @@ func (sm *streamManager) discover(ctx context.Context) (<-chan libp2p_peer.AddrI return nil, nil } - ctx, _ = context.WithTimeout(ctx, discTimeout) - return sm.pf.FindPeers(ctx, protoID, discBatch) + ctx2, cancel := context.WithTimeout(ctx, discTimeout) + go func() { // avoid context leak + <-time.After(discTimeout) + cancel() + }() + return sm.pf.FindPeers(ctx2, protoID, discBatch) } func (sm *streamManager) setupStreamWithPeer(ctx context.Context, pid libp2p_peer.ID) error { diff --git a/rosetta/services/construction_create.go b/rosetta/services/construction_create.go index 66135ce4c..f5e0f4ae2 100644 --- a/rosetta/services/construction_create.go +++ b/rosetta/services/construction_create.go @@ -112,9 +112,9 @@ func unpackWrappedTransactionFromString( Details: createValidatorMsg.Details, }, CommissionRates: stakingTypes.CommissionRates{ - Rate: numeric.Dec{createValidatorMsg.CommissionRate}, - MaxRate: numeric.Dec{createValidatorMsg.MaxCommissionRate}, - MaxChangeRate: numeric.Dec{createValidatorMsg.MaxChangeRate}, + Rate: numeric.Dec{Int: createValidatorMsg.CommissionRate}, + MaxRate: numeric.Dec{Int: createValidatorMsg.MaxCommissionRate}, + MaxChangeRate: numeric.Dec{Int: createValidatorMsg.MaxChangeRate}, }, MinSelfDelegation: createValidatorMsg.MinSelfDelegation, MaxTotalDelegation: createValidatorMsg.MaxTotalDelegation, @@ -156,7 +156,7 @@ func unpackWrappedTransactionFromString( SecurityContact: editValidatorMsg.SecurityContact, Details: editValidatorMsg.Details, }, - CommissionRate: &numeric.Dec{editValidatorMsg.CommissionRate}, + CommissionRate: &numeric.Dec{Int: editValidatorMsg.CommissionRate}, MinSelfDelegation: editValidatorMsg.MinSelfDelegation, MaxTotalDelegation: editValidatorMsg.MaxTotalDelegation, SlotKeyToAdd: slotKeyToAdd.(*bls.SerializedPublicKey), diff --git a/rosetta/services/construction_create_test.go b/rosetta/services/construction_create_test.go index 6d424223b..f634a98c0 100644 --- a/rosetta/services/construction_create_test.go +++ b/rosetta/services/construction_create_test.go @@ -480,9 +480,9 @@ func stakingCreateValidatorTransaction(key *ecdsa.PrivateKey) (*stakingTypes.Sta Details: "Don't mess with me!!!", }, CommissionRates: stakingTypes.CommissionRates{ - Rate: numeric.Dec{new(big.Int).SetUint64(100000000000000000)}, - MaxRate: numeric.Dec{new(big.Int).SetUint64(900000000000000000)}, - MaxChangeRate: numeric.Dec{new(big.Int).SetUint64(50000000000000000)}, + Rate: numeric.Dec{Int: new(big.Int).SetUint64(100000000000000000)}, + MaxRate: numeric.Dec{Int: new(big.Int).SetUint64(900000000000000000)}, + MaxChangeRate: numeric.Dec{Int: new(big.Int).SetUint64(50000000000000000)}, }, MinSelfDelegation: new(big.Int).Mul(new(big.Int).SetInt64(10), big.NewInt(1e18)), MaxTotalDelegation: new(big.Int).Mul(new(big.Int).SetInt64(3000), big.NewInt(1e18)), @@ -531,7 +531,7 @@ func stakingEditValidatorTransaction(key *ecdsa.PrivateKey) (*stakingTypes.Staki SecurityContact: "Bob", Details: "Don't mess with me!!!", }, - CommissionRate: &numeric.Dec{new(big.Int).SetUint64(100000000000000000)}, + CommissionRate: &numeric.Dec{Int: new(big.Int).SetUint64(100000000000000000)}, MinSelfDelegation: new(big.Int).Mul(new(big.Int).SetInt64(10), big.NewInt(1e18)), MaxTotalDelegation: new(big.Int).Mul(new(big.Int).SetInt64(3000), big.NewInt(1e18)), SlotKeyToRemove: &slotKeyToRemove, diff --git a/rosetta/services/tx_construction.go b/rosetta/services/tx_construction.go index e3fbc29a0..be93b076d 100644 --- a/rosetta/services/tx_construction.go +++ b/rosetta/services/tx_construction.go @@ -215,9 +215,9 @@ func constructCreateValidatorTransaction( Details: createValidatorMsg.Details, }, CommissionRates: types2.CommissionRates{ - Rate: numeric.Dec{createValidatorMsg.CommissionRate}, - MaxRate: numeric.Dec{createValidatorMsg.MaxCommissionRate}, - MaxChangeRate: numeric.Dec{createValidatorMsg.MaxChangeRate}, + Rate: numeric.Dec{Int: createValidatorMsg.CommissionRate}, + MaxRate: numeric.Dec{Int: createValidatorMsg.MaxCommissionRate}, + MaxChangeRate: numeric.Dec{Int: createValidatorMsg.MaxChangeRate}, }, MinSelfDelegation: new(big.Int).Mul(createValidatorMsg.MinSelfDelegation, big.NewInt(1e18)), MaxTotalDelegation: new(big.Int).Mul(createValidatorMsg.MaxTotalDelegation, big.NewInt(1e18)), @@ -286,7 +286,7 @@ func constructEditValidatorTransaction( SecurityContact: editValidatorMsg.SecurityContact, Details: editValidatorMsg.Details, }, - CommissionRate: &numeric.Dec{editValidatorMsg.CommissionRate}, + CommissionRate: &numeric.Dec{Int: editValidatorMsg.CommissionRate}, MinSelfDelegation: new(big.Int).Mul(editValidatorMsg.MinSelfDelegation, big.NewInt(1e18)), MaxTotalDelegation: new(big.Int).Mul(editValidatorMsg.MaxTotalDelegation, big.NewInt(1e18)), SlotKeyToAdd: &slotKeyToAdd, diff --git a/rpc/common/types.go b/rpc/common/types.go index e987d6cea..3fc514429 100644 --- a/rpc/common/types.go +++ b/rpc/common/types.go @@ -68,7 +68,7 @@ type NodeMetadata struct { PeerID peer.ID `json:"peerid"` Consensus ConsensusInternal `json:"consensus"` C C `json:"p2p-connectivity"` - SyncPeers map[string]int `json:"sync-peers",omitempty` + SyncPeers map[string]int `json:"sync-peers,omitempty"` } // P captures the connected peers per topic diff --git a/rpc/tracer.go b/rpc/tracer.go index fe93eb378..a5d7deac4 100644 --- a/rpc/tracer.go +++ b/rpc/tracer.go @@ -77,25 +77,28 @@ func (s *PublicTracerService) TraceChain(ctx context.Context, start, end rpc.Blo // TODO (JL): Make API available after DoS testing return nil, ErrNotAvailable - if uint64(start) >= uint64(end) { - return nil, fmt.Errorf("start block can not be equal or greater than the end block") - } + /* + if uint64(start) >= uint64(end) { + return nil, fmt.Errorf("start block can not be equal or greater than the end block") + } - currentBlock := s.hmy.BlockChain.CurrentBlock().NumberU64() - if uint64(start) > currentBlock || uint64(end) > currentBlock { - return nil, ErrRequestedBlockTooHigh - } + currentBlock := s.hmy.BlockChain.CurrentBlock().NumberU64() + if uint64(start) > currentBlock || uint64(end) > currentBlock { + return nil, ErrRequestedBlockTooHigh + } - from := s.hmy.BlockChain.GetBlockByNumber(uint64(start)) - if from == nil { - return nil, fmt.Errorf("start block #%d not found", start) - } - to := s.hmy.BlockChain.GetBlockByNumber(uint64(end)) - if to == nil { - return nil, fmt.Errorf("end block #%d not found", end) - } + from := s.hmy.BlockChain.GetBlockByNumber(uint64(start)) + if from == nil { + return nil, fmt.Errorf("start block #%d not found", start) + } + to := s.hmy.BlockChain.GetBlockByNumber(uint64(end)) + if to == nil { + return nil, fmt.Errorf("end block #%d not found", end) + } + + return s.hmy.TraceChain(ctx, from, to, config) - return s.hmy.TraceChain(ctx, from, to, config) + */ } // TraceBlockByNumber returns the structured logs created during the execution of diff --git a/scripts/golint.sh b/scripts/golint.sh index f6327f173..8beada007 100755 --- a/scripts/golint.sh +++ b/scripts/golint.sh @@ -4,5 +4,4 @@ case "${0}" in */*) progdir="${0%/*}";; *) progdir=.;; esac -"${progdir}/list_harmony_go_files.sh" | "${progdir}/dirnames.sh" | \ - sort -u -t/ | xargs golint "$@" +go vet ./... diff --git a/shard/committee/assignment.go b/shard/committee/assignment.go index b0d576bef..ccfcdca90 100644 --- a/shard/committee/assignment.go +++ b/shard/committee/assignment.go @@ -197,9 +197,9 @@ func prepareOrders( totalStaked.Add(totalStaked, validatorStake) essentials[validator.Address] = &effective.SlotOrder{ - validatorStake, - validator.SlotPubKeys, - tempZero, + Stake: validatorStake, + SpreadAmong: validator.SlotPubKeys, + Percentage: tempZero, } } totalStakedDec := numeric.NewDecFromBigInt(totalStaked) @@ -291,9 +291,8 @@ func preStakingEnabledCommittee(s shardingconfig.Instance) (*shard.State, error) return nil, err } curNodeID := shard.Slot{ - addr, - pubKey, - nil, + EcdsaAddress: addr, + BLSPublicKey: pubKey, } com.Slots = append(com.Slots, curNodeID) } @@ -310,9 +309,8 @@ func preStakingEnabledCommittee(s shardingconfig.Instance) (*shard.State, error) return nil, err } curNodeID := shard.Slot{ - addr, - pubKey, - nil, + EcdsaAddress: addr, + BLSPublicKey: pubKey, } com.Slots = append(com.Slots, curNodeID) } @@ -331,7 +329,7 @@ func eposStakedCommittee( shardHarmonyNodes := s.NumHarmonyOperatedNodesPerShard() for i := 0; i < shardCount; i++ { - shardState.Shards[i] = shard.Committee{uint32(i), shard.SlotList{}} + shardState.Shards[i] = shard.Committee{ShardID: uint32(i), Slots: shard.SlotList{}} for j := 0; j < shardHarmonyNodes; j++ { index := i + j*shardCount pub := &bls_core.PublicKey{} @@ -348,9 +346,8 @@ func eposStakedCommittee( return nil, err } shardState.Shards[i].Slots = append(shardState.Shards[i].Slots, shard.Slot{ - addr, - pubKey, - nil, + EcdsaAddress: addr, + BLSPublicKey: pubKey, }) } } @@ -368,9 +365,9 @@ func eposStakedCommittee( shardID := int(new(big.Int).Mod(purchasedSlot.Key.Big(), shardBig).Int64()) shardState.Shards[shardID].Slots = append( shardState.Shards[shardID].Slots, shard.Slot{ - purchasedSlot.Addr, - purchasedSlot.Key, - &purchasedSlot.EPoSStake, + EcdsaAddress: purchasedSlot.Addr, + BLSPublicKey: purchasedSlot.Key, + EffectiveStake: &purchasedSlot.EPoSStake, }, ) } diff --git a/shard/shard_state.go b/shard/shard_state.go index 74edeff36..8b8ca6f14 100644 --- a/shard/shard_state.go +++ b/shard/shard_state.go @@ -339,7 +339,7 @@ func (c *Committee) BLSPublicKeys() ([]bls.PublicKeyWrapper, error) { return nil, err } - slice[j] = bls.PublicKeyWrapper{c.Slots[j].BLSPublicKey, pubKey} + slice[j] = bls.PublicKeyWrapper{Bytes: c.Slots[j].BLSPublicKey, Object: pubKey} } return slice, nil diff --git a/staking/slash/double-sign.go b/staking/slash/double-sign.go index 20c483c99..cd26214b6 100644 --- a/staking/slash/double-sign.go +++ b/staking/slash/double-sign.go @@ -130,7 +130,7 @@ func (r Record) MarshalJSON() ([]byte, error) { common2.MustAddressToBech32(r.Evidence.Offender) return json.Marshal(struct { Evidence Evidence `json:"evidence"` - Reporter string `json:"reporter"` + Beneficiary string `json:"beneficiary"` AddressForBLSKey string `json:"offender"` }{r.Evidence, reporter, offender}) } diff --git a/staking/types/validator.go b/staking/types/validator.go index 91245a2be..14dfc3ce9 100644 --- a/staking/types/validator.go +++ b/staking/types/validator.go @@ -79,9 +79,9 @@ type ValidatorSnapshotReader interface { type counters struct { // The number of blocks the validator // should've signed when in active mode (selected in committee) - NumBlocksToSign *big.Int `json:"to-sign",rlp:"nil"` + NumBlocksToSign *big.Int `json:"to-sign" rlp:"nil"` // The number of blocks the validator actually signed - NumBlocksSigned *big.Int `json:"signed",rlp:"nil"` + NumBlocksSigned *big.Int `json:"signed" rlp:"nil"` } // ValidatorWrapper contains validator, diff --git a/test/chain/reward/main.go b/test/chain/reward/main.go index 3d5280ed4..6d78f4dd8 100644 --- a/test/chain/reward/main.go +++ b/test/chain/reward/main.go @@ -121,10 +121,8 @@ func main() { } for i := 0; i < 100000; i++ { validator.Delegations = append(validator.Delegations, staking.Delegation{ - common2.Address{}, - big.NewInt(int64(rand.Intn(100))), - big.NewInt(0), - nil, + Amount: big.NewInt(int64(rand.Intn(100))), + Reward: big.NewInt(0), }) } diff --git a/test/chain/vrf/main.go b/test/chain/vrf/main.go index d55247815..1a44b9e41 100644 --- a/test/chain/vrf/main.go +++ b/test/chain/vrf/main.go @@ -36,7 +36,7 @@ func main() { startTime = time.Now() for i := 0; i < size; i++ { if !sig.VerifyHash(pubKeyWrapper.Object, blockHash[:]) { - fmt.Errorf("failed to verify sig") + fmt.Println("failed to verify sig") } } endTime = time.Now() @@ -99,7 +99,7 @@ func main() { startTime = time.Now() if !aggSig.VerifyHash(aggPub, blockHash[:]) { - fmt.Errorf("failed to verify sig") + fmt.Println("failed to verify sig") } endTime = time.Now() diff --git a/tools/tools.go b/tools/tools.go index cd84b514c..47fbf1fe9 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -2,6 +2,7 @@ // builds, which would fail because the imports are programs – package main – // and not really importable packages. // +//go:build tools // +build tools // Package tools provides build tools necessary for Harmony. @@ -13,7 +14,4 @@ import ( _ "github.com/golang/mock/mockgen" _ "github.com/golang/protobuf/protoc-gen-go" _ "github.com/golangci/golangci-lint/cmd/golangci-lint" - _ "github.com/harmony-ek/gencodec" - _ "golang.org/x/lint/golint" - _ "golang.org/x/tools/cmd/goimports" )