Skip to content

Commit

Permalink
chore(consensus): stabilize consensus algorithm (#284)
Browse files Browse the repository at this point in the history
* fix: fix the most of the compile errors

* chore: update import section

* fix: regenerate remote_client.go mock, some fixes by feedback

* fix: remove unused global variables

* fix: some fixes for 0.35 backport

* fix: some fixes for 0.35 backport

* fix(evidence): fix all failed tests in evidence package

* fix(store): fix unit tests for internal/store package

* fix(blocksync): fix unit tests for internal/blocksync package

* fix(p2p): remove redundant sleep from TestMConnTransport_Listen

* fix(blocksync): fic blocksync/v2 test

* fix(rpc): allow reading "request_quorum_info" param for rpc "validators" handler

* fix(state): fix internal/state package

* fix(state): fix internal/statesync package

* fix(test): fix internal/test/factory package

* fix(privval): some fixes for unit tests

* fix(privval): fix tests TestPrivvalVectors, TestStateSyncVectors

* fix(consensus): fix consensus logic and tests

* fix: remove generating AppHash from genesis

* fix: remove debug printing

* fix(mempool): fix TestSerialReap

* fix(rpc): fix TestBroadcastEvidence_DuplicateVoteEvidence

* fix: cycle dependency in "types" package

* fix(types): modify and remove some test in types package

* refactor: remove unnecessary type conversion, update comment docs

* fix: light client package

* refactor: improve validator-set generator

* fix: some modification to ber able to run unit tests

* fix: increase MaxHeaderBytes till 646 bytes

* fix: TestTxFilter unit test at tx_filter_test.go

* fix: TestGCFifo, TestGCRandom, reduce a size of elements to 100

* fix: e2e generator, remove UnmixedP2P and Legacy test cases

* refactor: remove a few unused variables and functions, clean up the code

* fix: modify building of a docker image for e2e, update dashcore.toml

* refactor: modification after PR feedback

* fix: some modifications to fix e2e test

* wip

* fix: revert Client.getLightBlock fom upstream to be able to handle "deadline exceeded" properly

* chore: clearing code from temporary debug logs

* refactor: reduce timeout for requesting node status from e2e runner

* fix: update LastStateID and LastCoreChainLockedBlockHeight during state synchronization

* fix: add a task for compiling tests to main tasks in e2e Makefile

* fix: modify dashcore.toml

* fix: modify a light client to use default height as 0

* fix: update code style

* chore: revert logging to upstream version

* refactor: increased timeout from 20 sec to 30 sec due to sometimes node needs a bit more time to sync

* refactor: revert Client.compareNewHeaderWithWitness to upstream version

* fix: remove redeclared imported package

* fix: RPCStateProvider uses "truest-height" as initial height for downloading

* refactor: sync dashcore.toml with ci.toml

* fix(node): change TestMaxProposalBlockSize test to support tenderdash values and behaviour

* fix(ci): modify coverage.yml

* fix: modify app/app/test.sh after backport v0.35

* fix: update coverage.yml git workflow

* fix: make changes to fix lint issues using the golangci-lint report form

* fix: make changes to fix lint issues using the golangci-lint report form

* wip

* Fix compiling of tenderdash for arm architecture (#257)

* fix: remove bls-signatures from deps of build-linux task
* fix: add "post setup go" task to replace installed go version  in /bin directory

* fix: add sudo to install tenderdash

* chore(backport): revert changes

* chore: replace default go version in /bin on go 1.17

* fix: use a copy of "Precommit" fo fix a race condition

* chore: remove condition at "post-setup go 1.17"

* chore: revert to previous version

* chore: reduce timeout to 20 sec for waiting for nodes

* chore: increased wait-for-height timeout to 1 min

* chore: update dashcore.toml

* chore: remove duplicated debug log entry

* chore: modify of counting validators for e2e testnet

* chore: fix minor lint issue

* chore: modyfy rotate.toml

* chore: update e2e.yml CI settings

* chore: change log level for e2e

* refactor: change an approach  of updating a node keys and proTxHash (for validator)

* chore: update dashcore.toml and rotate.toml

* refactor: update preparing testnet settings for e2e

* refactor: declare Validator interface, add implementation of this interface for PubKey, refactor public key validation in validateValidatorUpdates function

* chore: fix a couple of lint issues and remove redundant debug printing

* chore: add missed code to control the proof block creation algorithm.

* refactor: change a type of node proTxHash from pointer

* feat: define NodeInfoRepository and implement it in PeerManager to be able to store NodeInfo

* fix: p2p/switch_test.go

* chore: change names of field and options function related to  node-info repository

* fix: decode peer-state into json byte slice manually to prevent data race

* fix: extend MockPV synchronization for several exportable methods

* chore: modify after merge

* chore: update timeouts and entrypoint for running e2e tests

* fix: modify and fix e2e implementation

* fix: some stabilization changes for light client implementation

* refactor: implement a validation of public key as a part of a key itself, that is used in block execution process

* fix: some modifications for statesync

* fix: update NodeInfo.ProTxHash for validator node during node initialization

* refactor: add "ProTxHashValidate" function

* refactor: add proTxHash field into PeerInfo protobuf

* refactor: add proTxHash in peerInfo

* refactor: move the code that routerDashDialer is not responsible into PeerManager

* refactor: define DashDialerOptions struct to be able to provide NodeAddress and ProTxHash,  change a signature of the method ConnectAsync in DashDialer

* chore: update doc blocks for DashDialer(s)

* refactor: support ProTxHash in p2ptest

* refactor: improve HexByte.ShortString, if the length is not enough then return an empty string

* refactor: revert DashDialer and ValidatorConnExecutor to initial version

* feat: retrieve proTxHash from NodeInfo struct after handshake, add proTxHash to PeerUpdate and PeerState

* fix: check peer-info for existence before to retrieve proTxHash for persisting

* refactor: remove all references to NodeInfoRepository

* chore: remove a couple of redundant methods after the merge

* chore: fix typo

* chore: temporary disable tcp NodeID resolver as it breaks running ValidatorConnExecutor component

* chore: disable updating-connections for genesis/init-chain validators

* fix(consensus): Decrease memory used by debug logs

* refactor: enhance performance of getLogFields func

* chore(consensus): further optimization of logging mem usage

* fix: modify after merge

* fix(dash/quorum): tendermint stops when remote validator node id lookup fails

* fix(p2p): remove noisy logs from p2p package

In DEBUG log level, we did create tons of P2P logs that severely affects
performance and disk usage.

* fix: peer proTxHash is empty in PeerState

* chore: remove redundant log file

* fix: vote channel size too small for commit messages

* fix: deadlock in PeerState

* fix(consensus): fix race condition in processPeerUpdate

* fix(dash/qorum): don't try to connect to myself

* fix(p2p): proTxHash not updated for incoming connections

* build(e2e): enable deadlock detection in e2e tests

* refactor(consensus): improve logging

* test(e2e): enable debug logs in dashcore

* chore: try to fix commit exchange (WIP)

* fix(types): support zero ValidatorAddress

* test(p2p): fix p2p network tests

* fix(consensus): fix race conditions and deadlocks

* feat(sync): add lock timeout to deadlock detection library

* fix(reactor): panic fixed

* chore(sync): mutex debugging helper

* chore(types): Improve logging of validator sets

* chore(sync): set lock timeout to 30s

* refactor(dashcore): use Logger in dash core rpc client

* refactor(logging): log label "peer" instead of "peer_id"

* chore(statesync): logging improvements

* refactor(statesync): publish a commit event after successful sync operation

* fix(consensus): deep copy proTxHash in peer events

* fix(consensus): nodeID and proTxHash mismatch in consensus tests

* fix(sync): revert deadlock logic changes

* refactor(consensus): cleanup reactor gossip logic

* fix: detected and fix data race of reading validator's proTxHash for logging

* fix(consensus): don't panic on invalid vote

* fix(consensus): don't process votes when not a validator

* fix(p2p): dash dialer concurrent map access

* fix(e2e): e2e test of manifest generation

* refactor(e2e): add a feature to wait for a mockcoreserver is ready

* fix(consensus): detect and fix data race during update "round state" of a peer in gossipDataRoutine

* fix(typo): modify of an error log

* fix(consensus): the test TestReactorInvalidBlockChainLock has wrong order of clean up functions

* refactor(bits-array): fix potential deadlock in bit_array.go

* fix(consensus): don't try to send commit for height 0

* chore(types): improve logging

* chore(consensus): improve logging

* test(types): add proposal verification test for hardcoded proposal

* test(consensus): enable prevoting NIL in TestReactorValidatorSetChanges

* refactor(privval): remove some unused functions from file pv

* chore(p2p): apply peer review feedback

* refactor(statesync): publish a commit event after successful sync operation (#289)

* refactor(bits-array): fix potential deadlock in bit_array.go (#294)
* fix(ci): broken arm build (#295)
* fix(ci): update apt cache before install deps

* chore: remove a few files that were committed by accident

* chore: rollback error initializing

* chore: rollback one line function

* chore(consensus): apply code review feedback

Co-authored-by: shotonoff <[email protected]>
Co-authored-by: Dmitrii Golubev <[email protected]>
Co-authored-by: Dmitrii Golubev <[email protected]>
  • Loading branch information
4 people authored Mar 23, 2022
1 parent 8ccea22 commit 6d6ca1e
Show file tree
Hide file tree
Showing 65 changed files with 810 additions and 420 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ test/e2e/networks
test/logs
test/p2p/data
third_party/bls-signatures/build
*.log
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
if: matrix.goarch == 'amd64' && env.GIT_DIFF != ''
- name: build
run: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-8-arm-linux-gnueabihf
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++-8
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ ifeq (boltdb,$(findstring boltdb,$(TENDERMINT_BUILD_OPTIONS)))
BUILD_TAGS += boltdb
endif

# handle deadlock
ifeq (deadlock,$(findstring deadlock,$(TENDERMINT_BUILD_OPTIONS)))
BUILD_TAGS += deadlock
endif

# allow users to pass additional flags via the conventional LDFLAGS variable
LD_FLAGS += $(LDFLAGS)

Expand Down
3 changes: 2 additions & 1 deletion cmd/tenderdash/commands/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ func runProxy(cmd *cobra.Command, args []string) error {
light.DashCoreVerification(),
}

dashCoreRPCClient, _ := dashcore.NewRPCClient(dashCoreRPCHost, dashCoreRPCUser, dashCoreRPCPass)
rpcLogger := logger.With("module", dashcore.ModuleName)
dashCoreRPCClient, _ := dashcore.NewRPCClient(dashCoreRPCHost, dashCoreRPCUser, dashCoreRPCPass, rpcLogger)

c, err := light.NewHTTPClient(
context.Background(),
Expand Down
1 change: 1 addition & 0 deletions crypto/bls12381/bls12381.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sort"

bls "github.com/dashpay/bls-signatures/go-bindings"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/tmhash"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down
5 changes: 5 additions & 0 deletions dash/quorum/validator_conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ func (vc *ValidatorConnExecutor) updateConnections() error {
func (vc *ValidatorConnExecutor) filterAddresses(validators validatorMap) validatorMap {
filtered := make(validatorMap, len(validators))
for id, validator := range validators {
if vc.proTxHash != nil && string(id) == vc.proTxHash.String() {
vc.Logger.Debug("validator is ourself", "id", id, "address", validator.NodeAddress.String())
continue
}

if err := validator.ValidateBasic(); err != nil {
vc.Logger.Debug("validator address is invalid", "id", id, "address", validator.NodeAddress.String())
continue
Expand Down
18 changes: 15 additions & 3 deletions dashcore/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import (

"github.com/dashevo/dashd-go/btcjson"
rpc "github.com/dashevo/dashd-go/rpcclient"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/libs/log"
)

const ModuleName = "rpcclient"

type Client interface {
// QuorumInfo returns quorum info
QuorumInfo(quorumType btcjson.LLMQType, quorumHash crypto.QuorumHash) (*btcjson.QuorumInfoResult, error)
Expand Down Expand Up @@ -43,11 +47,12 @@ type Client interface {
// Handles connection to the underlying dashd instance
type RPCClient struct {
endpoint *rpc.Client
logger log.Logger
}

// NewRPCClient returns an instance of Client.
// it will start the endpoint (if not already started)
func NewRPCClient(host string, username string, password string) (*RPCClient, error) {
func NewRPCClient(host string, username string, password string, logger log.Logger) (*RPCClient, error) {
if host == "" {
return nil, fmt.Errorf("unable to establish connection to the Dash Core node")
}
Expand All @@ -67,7 +72,14 @@ func NewRPCClient(host string, username string, password string) (*RPCClient, er
return nil, err
}

dashCoreClient := RPCClient{endpoint: client}
if logger == nil {
return nil, fmt.Errorf("logger must be set")
}

dashCoreClient := RPCClient{
endpoint: client,
logger: logger,
}

return &dashCoreClient, nil
}
Expand Down Expand Up @@ -137,7 +149,7 @@ func (rpcClient *RPCClient) QuorumVerify(
signature bytes.HexBytes,
quorumHash crypto.QuorumHash,
) (bool, error) {
fmt.Printf("quorum verify sig %v quorumhash %s", signature, quorumHash)
rpcClient.logger.Debug("quorum verify", "sig", signature, "quorumhash", quorumHash)
return rpcClient.endpoint.QuorumVerify(
quorumType,
requestID.String(),
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ github.com/Workiva/go-datastructures v1.0.53 h1:J6Y/52yX10Xc5JjXmGtWoSSxs3mZnGSa
github.com/Workiva/go-datastructures v1.0.53/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5BnDuE2Ya2MMGhzP6A=
github.com/adlio/schema v1.2.3 h1:GfKThfEsjS9cCz7gaF8zdXv4cpTdUqdljkKGDTbJjys=
github.com/adlio/schema v1.2.3/go.mod h1:nD7ZWmMMbwU12Pqwg+qL0rTvHBrBXfNz+5UQxTfy38M=
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down Expand Up @@ -156,14 +155,11 @@ github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlH
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/goleveldb v1.0.0 h1:Tvd0BfvqX9o823q1j2UZ/epQo09eJh6dTcRp79ilIN4=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0 h1:ZxaA6lo2EpxGddsA8JwWOcxlzRybb444sgmeJQMJGQE=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/butuzov/ireturn v0.1.1 h1:QvrO2QF2+/Cx1WA/vETCIYBKtRjc30vesdoPUNo1EbY=
github.com/butuzov/ireturn v0.1.1/go.mod h1:Wh6Zl3IMtTpaIKbmwzqi6olnM9ptYQxxVacMsOEFPoc=
Expand Down Expand Up @@ -242,7 +238,6 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0 h1:/8DMNYp9SGi5f0w7uCm6d6M4OU2rGFK
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1m5sE92cU+pd5Mcc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/lru v1.0.0 h1:Kbsb1SFDsIlaupWPwsPp+dkxiBY1frcS07PCPgotKz8=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/denis-tingajkin/go-header v0.4.2 h1:jEeSF4sdv8/3cT/WY8AgDHUoItNSoEZ7qg9dX7pc218=
github.com/denis-tingajkin/go-header v0.4.2/go.mod h1:eLRHAVXzE5atsKAnNRDB90WHCFFnBUn4RN0nRcs1LJA=
Expand Down Expand Up @@ -588,7 +583,6 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jgautheron/goconst v1.5.1 h1:HxVbL1MhydKs8R8n/HE5NPvzfaYmQJA3o879lE4+WcM=
github.com/jgautheron/goconst v1.5.1/go.mod h1:aAosetZ5zaeC/2EfMeRswtxUFBpe2Hr7HzkgX4fanO4=
Expand All @@ -607,7 +601,6 @@ github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22
github.com/jonboulle/clockwork v0.2.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/josharian/txtarfs v0.0.0-20210218200122-0702f000015a/go.mod h1:izVPOvVRsHiKkeGCT6tYBNWyDVuzj9wAaBb5R9qamfw=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/jrick/logrotate v1.0.0 h1:lQ1bL/n9mBNeIXoTUoYRlK4dHuNJVofX9oWqBtPnSzI=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -633,7 +626,6 @@ github.com/kisielk/errcheck v1.6.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kkdai/bstream v1.0.0 h1:Se5gHwgp2VT2uHfDrkbbgbgEvV9cimLELwrPJctSjg8=
github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA=
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
Expand Down
2 changes: 1 addition & 1 deletion internal/blocksync/v0/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
newNode := rts.network.MakeNode(t, nil, p2ptest.NodeOptions{
MaxPeers: uint16(len(rts.nodes) + 1),
MaxConnected: uint16(len(rts.nodes) + 1),
})
}, log.TestingLogger())
rts.addNode(t, newNode.NodeID, otherGenDoc, otherPrivVals[0], maxBlockHeight)

// add a fake peer just so we do not wait for the consensus ticker to timeout
Expand Down
2 changes: 1 addition & 1 deletion internal/blocksync/v2/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (r *BlockchainReactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {
return
}

r.logger.Debug("received", "msg", msgProto)
// r.logger.Debug("received", "msg", msgProto)

switch msg := msgProto.Sum.(type) {
case *bcproto.Message_StatusRequest:
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) {
lazyNodeState.sendInternalMessage(msgInfo{&BlockPartMessage{lazyNodeState.Height, lazyNodeState.Round, part}, ""})
}
lazyNodeState.Logger.Info("Signed proposal", "height", height, "round", round, "proposal", proposal)
lazyNodeState.Logger.Debug(fmt.Sprintf("Signed proposal block: %v", block))
lazyNodeState.Logger.Debug("signed proposal block", "block", block)
} else if !lazyNodeState.replayMode {
lazyNodeState.Logger.Error("enterPropose: Error signing proposal", "height", height, "round", round, "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ func randConsensusNetWithPeers(

proTxHash, _ := privVal.GetProTxHash(context.Background())
css[i] = newStateWithConfig(thisConfig, state, privVal, app)
css[i].SetLogger(logger.With("validator", i, "proTxHash", proTxHash.ShortString(), "module", "consensus"))
css[i].SetLogger(logger.With("validator", i, "node_proTxHash", proTxHash.ShortString(), "module", "consensus"))
css[i].SetTimeoutTicker(tickerFunc())
}
return css, genDoc, peer0Config, func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/core_chainlock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestReactorInvalidBlockChainLock(t *testing.T) {
newMockTickerFunc(true),
newCounterWithBackwardsCoreChainLocks,
)
defer cleanup()
t.Cleanup(cleanup)

for i := 0; i < nVals; i++ {
ticker := NewTimeoutTicker()
Expand Down
42 changes: 28 additions & 14 deletions internal/consensus/peer_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type PeerState struct {
}

// NewPeerState returns a new PeerState for the given node ID.
func NewPeerState(logger log.Logger, peerID types.NodeID, proTxHash types.ProTxHash) *PeerState {
func NewPeerState(logger log.Logger, peerID types.NodeID) *PeerState {
return &PeerState{
peerID: peerID,
logger: logger,
Expand All @@ -60,8 +60,7 @@ func NewPeerState(logger log.Logger, peerID types.NodeID, proTxHash types.ProTxH
LastCommitRound: -1,
CatchupCommitRound: -1,
},
Stats: &peerStateStats{},
ProTxHash: proTxHash,
Stats: &peerStateStats{},
}
}

Expand All @@ -85,13 +84,20 @@ func (ps *PeerState) IsRunning() bool {
// GetRoundState returns a shallow copy of the PeerRoundState. There's no point
// in mutating it since it won't change PeerState.
func (ps *PeerState) GetRoundState() *cstypes.PeerRoundState {
ps.mtx.Lock()
defer ps.mtx.Unlock()
ps.mtx.RLock()
defer ps.mtx.RUnlock()

prs := ps.PRS.Copy()
return &prs
}

// UpdateRoundState ensures that the update function is called using the blocking mechanism
func (ps *PeerState) UpdateRoundState(fn func(prs *cstypes.PeerRoundState)) {
ps.mtx.Lock()
defer ps.mtx.Unlock()
fn(&ps.PRS)
}

// ToJSON returns a json of PeerState.
func (ps *PeerState) ToJSON() ([]byte, error) {
ps.mtx.Lock()
Expand Down Expand Up @@ -151,14 +157,15 @@ func (ps *PeerState) InitProposalBlockParts(partSetHeader types.PartSetHeader) {

// SetHasProposalBlockPart sets the given block part index as known for the peer.
func (ps *PeerState) SetHasProposalBlockPart(height int64, round int32, index int) {
ps.mtx.Lock()
defer ps.mtx.Unlock()

if ps.PRS.Height != height || ps.PRS.Round != round {
prs := ps.GetRoundState()
if prs.Height != height || prs.Round != round {
ps.logger.Debug("SetHasProposalBlockPart height/round mismatch",
"height", height, "round", round, "peer_height", prs.Height, "peer_round", prs.Round)
return
}

ps.mtx.Lock()
ps.PRS.ProposalBlockParts.SetIndex(index, true)
ps.mtx.Unlock()
}

// PickVoteToSend picks a vote to send to the peer. It will return true if a
Expand Down Expand Up @@ -368,10 +375,17 @@ func (ps *PeerState) RecordBlockPart() int {

// BlockPartsSent returns the number of useful block parts the peer has sent us.
func (ps *PeerState) BlockPartsSent() int {
ps.mtx.RLock()
defer ps.mtx.RUnlock()

return ps.Stats.BlockParts
}

func (ps *PeerState) SetProTxHash(proTxHash types.ProTxHash) {
ps.mtx.Lock()
defer ps.mtx.Unlock()

return ps.Stats.BlockParts
ps.ProTxHash = proTxHash.Copy()
}

// SetHasVote sets the given vote as known by the peer
Expand All @@ -386,7 +400,7 @@ func (ps *PeerState) setHasVote(height int64, round int32, voteType tmproto.Sign

ps.logger.Debug(
"peerState setHasVote",
"peer_id", ps.peerID,
"peer", ps.peerID,
"height", height,
"round", round,
"peer_height", ps.PRS.Height,
Expand Down Expand Up @@ -579,8 +593,8 @@ func (ps *PeerState) String() string {

// StringIndented returns a string representation of the PeerState
func (ps *PeerState) StringIndented(indent string) string {
ps.mtx.Lock()
defer ps.mtx.Unlock()
ps.mtx.RLock()
defer ps.mtx.RUnlock()
return fmt.Sprintf(`PeerState{
%s Key %v
%s RoundState %v
Expand Down
Loading

0 comments on commit 6d6ca1e

Please sign in to comment.