[project][node] bump max message handlers per topic, update deprecated/staticcheck finds (#2821)

* [rpc] Remove filter code - it is not used

* [node][project] Remove more dead code, bump max message handler to 200

* [rpc] Undo overzealous filter removal
pull/2823/head
Edgar Aroutiounian 5 years ago committed by GitHub
parent 27741f8407
commit 6c6006be44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      accounts/abi/abi_test.go
  2. 35
      accounts/abi/event_test.go
  3. 10
      accounts/keystore/passphrase.go
  4. 15
      api/client/service/server_test.go
  5. 12
      api/proto/message/errors.go
  6. 46
      api/proto/message/server.go
  7. 8
      hmy/api_backend.go
  8. 38
      internal/params/network_params.go
  9. 2
      node/node.go

@ -27,6 +27,7 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
@ -917,7 +918,9 @@ func TestABI_MethodByID(t *testing.T) {
}
b := fmt.Sprintf("%v", m2)
if a != b {
t.Errorf("Method %v (id %v) not 'findable' by id in ABI", name, common.ToHex(m.ID()))
t.Errorf("Method %v (id %v) not 'findable' by id in ABI",
name, hexutil.Encode(m.ID()),
)
}
}
// Also test empty

@ -173,7 +173,6 @@ func TestEventTupleUnpack(t *testing.T) {
type EventTransferWithTag struct {
// this is valid because `value` is not exportable,
// so value is only unmarshalled into `Value1`.
value *big.Int
Value1 *big.Int `abi:"value"`
}
@ -354,40 +353,6 @@ func unpackTestEventData(dest interface{}, hexData string, jsonEvent []byte, ass
return a.Unpack(dest, "e", data)
}
/*
Taken from
https://github.com/ethereum/go-ethereum/pull/15568
*/
type testResult struct {
Values [2]*big.Int
Value1 *big.Int
Value2 *big.Int
}
type testCase struct {
definition string
want testResult
}
func (tc testCase) encoded(intType, arrayType Type) []byte {
var b bytes.Buffer
if tc.want.Value1 != nil {
val, _ := intType.pack(reflect.ValueOf(tc.want.Value1))
b.Write(val)
}
if !reflect.DeepEqual(tc.want.Values, [2]*big.Int{nil, nil}) {
val, _ := arrayType.pack(reflect.ValueOf(tc.want.Values))
b.Write(val)
}
if tc.want.Value2 != nil {
val, _ := intType.pack(reflect.ValueOf(tc.want.Value2))
b.Write(val)
}
return b.Bytes()
}
// TestEventUnpackIndexed verifies that indexed field will be skipped by event decoder.
func TestEventUnpackIndexed(t *testing.T) {
definition := `[{"name": "test", "type": "event", "inputs": [{"indexed": true, "name":"value1", "type":"uint8"},{"indexed": false, "name":"value2", "type":"uint8"}]}]`

@ -117,7 +117,7 @@ func (ks keyStorePassphrase) StoreKey(filename string, key *Key, auth string) er
// Verify that we can decrypt the file with the given password.
_, err = ks.GetKey(key.Address, tmpName, auth)
if err != nil {
msg := "An error was encountered when saving and verifying the keystore file. \n" +
msg := "an error was encountered when saving and verifying the keystore file. \n" +
"This indicates that the keystore is corrupted. \n" +
"The corrupted file is stored at \n%v\n" +
"Please file a ticket at:\n\n" +
@ -238,7 +238,7 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) {
// DecryptDataV3 ...
func DecryptDataV3(cj CryptoJSON, auth string) ([]byte, error) {
if cj.Cipher != "aes-128-ctr" {
return nil, fmt.Errorf("Cipher not supported: %v", cj.Cipher)
return nil, fmt.Errorf("cipher not supported: %v", cj.Cipher)
}
mac, err := hex.DecodeString(cj.MAC)
if err != nil {
@ -274,7 +274,7 @@ func DecryptDataV3(cj CryptoJSON, auth string) ([]byte, error) {
func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byte, keyID []byte, err error) {
if keyProtected.Version != version {
return nil, nil, fmt.Errorf("Version not supported: %v", keyProtected.Version)
return nil, nil, fmt.Errorf("version not supported: %v", keyProtected.Version)
}
keyID = uuid.Parse(keyProtected.ID)
plainText, err := DecryptDataV3(keyProtected.Crypto, auth)
@ -336,13 +336,13 @@ func getKDFKey(cryptoJSON CryptoJSON, auth string) ([]byte, error) {
c := ensureInt(cryptoJSON.KDFParams["c"])
prf := cryptoJSON.KDFParams["prf"].(string)
if prf != "hmac-sha256" {
return nil, fmt.Errorf("Unsupported PBKDF2 PRF: %s", prf)
return nil, fmt.Errorf("unsupported PBKDF2 PRF: %s", prf)
}
key := pbkdf2.Key(authArray, salt, c, dkLen, sha256.New)
return key, nil
}
return nil, fmt.Errorf("Unsupported KDF: %s", cryptoJSON.KDF)
return nil, fmt.Errorf("unsupported KDF: %s", cryptoJSON.KDF)
}
// TODO: can we do without this when unmarshalling dynamic JSON?

@ -2,6 +2,7 @@ package client
import (
"bytes"
"context"
"math/big"
"testing"
@ -39,12 +40,15 @@ func TestGetFreeToken(test *testing.T) {
testBankKey, _ := crypto.GenerateKey()
testBankAddress := crypto.PubkeyToAddress(testBankKey.PublicKey)
response, err := server.GetFreeToken(nil, &client.GetFreeTokenRequest{Address: testBankAddress.Bytes()})
response, err := server.GetFreeToken(
context.TODO(),
&client.GetFreeTokenRequest{Address: testBankAddress.Bytes()},
)
if err != nil {
test.Errorf("Failed to get free token")
}
if bytes.Compare(response.TxId, hash.Bytes()) != 0 {
if !bytes.Equal(response.TxId, hash.Bytes()) {
test.Errorf("Wrong transaction id is returned")
}
}
@ -72,13 +76,16 @@ func TestFetchAccountState(test *testing.T) {
return hash
})
response, err := server.FetchAccountState(nil, &client.FetchAccountStateRequest{Address: testBankAddress.Bytes()})
response, err := server.FetchAccountState(
context.TODO(),
&client.FetchAccountStateRequest{Address: testBankAddress.Bytes()},
)
if err != nil {
test.Errorf("Failed to get free token")
}
if bytes.Compare(response.Balance, testBankFunds.Bytes()) != 0 {
if !bytes.Equal(response.Balance, testBankFunds.Bytes()) {
test.Errorf("Wrong balance is returned")
}

@ -1,12 +0,0 @@
package message
import "errors"
// Error of host package
var (
ErrWrongMessage = errors.New("Error as receiving wrong message")
ErrEnterMethod = errors.New("Error when processing enter method")
ErrResultMethod = errors.New("Error when processing result/getPlayers method")
ErrEnterProcessorNotReady = errors.New("Error because enter processor is not ready")
ErrWhenPickingWinner = errors.New("Error when picking winner")
)

@ -6,9 +6,7 @@ import (
"math/big"
"net"
"github.com/ethereum/go-ethereum/crypto"
"github.com/harmony-one/harmony/internal/utils"
"google.golang.org/grpc"
)
@ -28,50 +26,6 @@ type Server struct {
// Process processes the Message and returns Response
func (s *Server) Process(ctx context.Context, message *Message) (*Response, error) {
if message.GetType() != MessageType_LOTTERY_REQUEST {
return &Response{}, ErrWrongMessage
}
lotteryRequest := message.GetLotteryRequest()
if lotteryRequest.GetType() == LotteryRequest_ENTER {
if s.CreateTransactionForEnterMethod == nil {
return nil, ErrEnterProcessorNotReady
}
amount := lotteryRequest.Amount
priKey := lotteryRequest.PrivateKey
key, err := crypto.HexToECDSA(priKey)
if err != nil {
utils.Logger().Error().Msg("Error when HexToECDSA")
}
address := crypto.PubkeyToAddress(key.PublicKey)
utils.Logger().Info().Int64("amount", amount).Hex("address", address[:]).Msg("Enter")
if err := s.CreateTransactionForEnterMethod(amount, priKey); err != nil {
return nil, ErrEnterMethod
}
return &Response{}, nil
} else if lotteryRequest.GetType() == LotteryRequest_RESULT {
players, balances := s.GetResult(lotteryRequest.PrivateKey)
stringBalances := []string{}
for _, balance := range balances {
stringBalances = append(stringBalances, balance.String())
}
utils.Logger().Info().Strs("players", players).Strs("balances", stringBalances).Msg("getPlayers")
ret := &Response{
Response: &Response_LotteryResponse{
LotteryResponse: &LotteryResponse{
Players: players,
Balances: stringBalances,
},
},
}
return ret, nil
} else if lotteryRequest.GetType() == LotteryRequest_PICK_WINNER {
if s.CreateTransactionForPickWinner() != nil {
return nil, ErrWhenPickingWinner
}
return &Response{}, nil
}
return &Response{}, nil
}

@ -129,11 +129,17 @@ func (b *APIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.R
// TODO: this is not implemented or verified yet for harmony.
func (b *APIBackend) EventMux() *event.TypeMux { return b.hmy.eventMux }
const (
// BloomBitsBlocks is the number of blocks a single bloom bit section vector
// contains on the server side.
BloomBitsBlocks uint64 = 4096
)
// BloomStatus ...
// TODO: this is not implemented or verified yet for harmony.
func (b *APIBackend) BloomStatus() (uint64, uint64) {
sections, _, _ := b.hmy.bloomIndexer.Sections()
return params.BloomBitsBlocks, sections
return BloomBitsBlocks, sections
}
// ProtocolVersion ...

@ -1,38 +0,0 @@
package params
// These are network parameters that need to be constant between clients, but
// aren't necessarily consensus related.
const (
// BloomBitsBlocks is the number of blocks a single bloom bit section vector
// contains on the server side.
BloomBitsBlocks uint64 = 4096
// BloomBitsBlocksClient is the number of blocks a single bloom bit section vector
// contains on the light client side
BloomBitsBlocksClient uint64 = 32768
// BloomConfirms is the number of confirmation blocks before a bloom section is
// considered probably final and its rotated bits are calculated.
BloomConfirms = 256
// CHTFrequencyClient is the block frequency for creating CHTs on the client side.
CHTFrequencyClient = 32768
// CHTFrequencyServer is the block frequency for creating CHTs on the server side.
// Eventually this can be merged back with the client version, but that requires a
// full database upgrade, so that should be left for a suitable moment.
CHTFrequencyServer = 4096
// BloomTrieFrequency is the block frequency for creating BloomTrie on both
// server/client sides.
BloomTrieFrequency = 32768
// HelperTrieConfirmations is the number of confirmations before a client is expected
// to have the given HelperTrie available.
HelperTrieConfirmations = 2048
// HelperTrieProcessConfirmations is the number of confirmations before a HelperTrie
// is generated
HelperTrieProcessConfirmations = 256
)

@ -362,7 +362,7 @@ func (node *Node) Start() error {
return errors.New("have no topics to listen to")
}
weighted := make([]*semaphore.Weighted, len(allTopics))
const maxMessageHandlers = 100
const maxMessageHandlers = 200
ctx := context.Background()
ownID := node.host.GetID()
errChan := make(chan error)

Loading…
Cancel
Save