Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(dot/network, lib/grandpa): fix handshake decoding and grandpa message handler sigabort #1631

Merged
merged 104 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
5a38145
update README.md
noot May 13, 2021
117ebb8
update docs
noot May 13, 2021
c834e99
update gssmr genesis file to have 6 auths
noot May 13, 2021
2fca3d8
Merge branch 'development' into noot/update-readme
noot May 13, 2021
70b794e
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 13, 2021
b5ba601
add peercount to network logs
noot May 13, 2021
02faa96
update log order
noot May 13, 2021
09e8ca9
Merge branch 'development' into noot/update-readme
dutterbutter May 14, 2021
2943b15
Merge branch 'noot/devnet' of github.com:ChainSafe/gossamer into noot…
noot May 14, 2021
5d09224
update logs
noot May 14, 2021
d6e13f8
add log
noot May 14, 2021
332ff24
change DHT mode to ModeServer, add peersToTry map
noot May 14, 2021
c2175f5
lint
noot May 14, 2021
4f35500
fix loop logic in beginDiscovery
noot May 14, 2021
e0dce6a
add advertising logic
noot May 14, 2021
6246ce1
lint
noot May 14, 2021
65a021b
increase intial advertise ttl
noot May 14, 2021
e4417e4
bootstrap dht before advertise
noot May 14, 2021
f444e14
fix
noot May 14, 2021
d78eaa8
add discovery submodule; wait for peers before starting DHT
noot May 14, 2021
f67be8a
add logs
noot May 14, 2021
2578344
add package to get public IP
noot May 14, 2021
bc808a5
add routing table refresh
noot May 14, 2021
2233927
remove routing table refresh
noot May 14, 2021
1b87f0d
fix some tests
noot May 14, 2021
0525703
remove advertisement
noot May 17, 2021
63709f6
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 18, 2021
1f91b09
readd advertisement
noot May 18, 2021
acb5df1
cleanup
noot May 18, 2021
0960e47
revert genesis files
noot May 18, 2021
d984743
re-enable test
noot May 18, 2021
d3e47c0
update log levels
noot May 18, 2021
46bdf5c
decrease time before advertising
noot May 18, 2021
453660b
restore bootstrap order
noot May 18, 2021
47899b2
decrease failed to advertise ttl
noot May 18, 2021
62d9f28
cleanup, add constants
noot May 18, 2021
92bac0c
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 18, 2021
9dc4efb
log cleanup
noot May 18, 2021
49781d9
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 18, 2021
165743e
update runtime c=3/4 (1/4 probability of empty slot)
noot May 18, 2021
314071d
update gossamer genesis.json
noot May 18, 2021
c93bcab
merge w fix-discovery
noot May 18, 2021
50926ed
merge w development
noot May 21, 2021
326d8dc
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 25, 2021
7f3a59f
update to 3 auth genesis
noot May 25, 2021
7ed2854
pause BABE when syncing
noot May 25, 2021
1df3929
check err
noot May 25, 2021
d7fcbbb
send block response even if missing some data
noot May 25, 2021
3e1d662
restore 6 auths in genesis for babe
noot May 25, 2021
caf07cf
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 26, 2021
320bae5
add snapshot in StorageState.StoreTrie
noot May 26, 2021
2abd107
cleanups
noot May 26, 2021
6d01dcd
cleanup
noot May 26, 2021
0bb1c5b
lock StoreTrie the whole time
noot May 26, 2021
9d220a7
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 28, 2021
01bd01c
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 28, 2021
ed05cb7
add go.mod
noot May 28, 2021
ad8d48d
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot May 31, 2021
5fa2a7e
merge w development
noot May 31, 2021
3057240
add state logs
noot May 31, 2021
42ff15e
add state logs
noot May 31, 2021
7a7f294
fix
noot May 31, 2021
65e1e45
update trie.Snapshot to return new trie
noot May 31, 2021
f9d04f2
fix
noot May 31, 2021
c53b174
update tests for updated trie.Snapshot
noot May 31, 2021
b7bf025
lint
noot May 31, 2021
52cc4a6
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Jun 1, 2021
4623d7a
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Jun 2, 2021
3706836
decrease connectToPeersTimeout
noot Jun 2, 2021
edd142e
change log lvl for handshakes
noot Jun 2, 2021
3b330f7
fix sendData to use correct handshakeDecoder
noot Jun 3, 2021
5d52006
add logs, try to fix sigabrt
noot Jun 3, 2021
8d60ef2
add logs, try to fix sigabrt
noot Jun 3, 2021
214784c
add nil checks
noot Jun 3, 2021
7c4cd23
add log
noot Jun 3, 2021
ab21bb8
add log
noot Jun 3, 2021
5bfb710
slightly increase sleep in attemptToFinalize
noot Jun 3, 2021
c52ddaf
Merge branch 'noot/fix-devnet-sync' of github.com:ChainSafe/gossamer …
noot Jun 4, 2021
151ff95
update babe locks
noot Jun 4, 2021
01ea9da
add modified genesis file
noot Jun 4, 2021
4df4c10
remove changes except trie.Snapshot update
noot Jun 4, 2021
e4d3762
Merge branch 'development' of github.com:ChainSafe/gossamer into noot…
noot Jun 4, 2021
89f944b
fix
noot Jun 4, 2021
69bcc45
cleanup
noot Jun 4, 2021
291588e
fix
noot Jun 4, 2021
adc8eb9
merge w development
noot Jun 4, 2021
9761303
don't sendData in goroutine
noot Jun 4, 2021
658242e
comment out grandpa msg handling except VoteMessage
noot Jun 7, 2021
e3b81e3
reset dev cfg
noot Jun 7, 2021
160f0e7
merge w base branch
noot Jun 7, 2021
d690643
fix
noot Jun 7, 2021
03182fa
fix
noot Jun 7, 2021
19cc490
Merge branch 'development' into noot/fix-devnet-sync
noot Jun 7, 2021
fe5f186
attempting to debug
noot Jun 8, 2021
94e69b2
Merge branch 'development' into noot/fix-devnet-sync
noot Jun 8, 2021
d730f53
fix siagbrt
noot Jun 9, 2021
9a848bd
remove network sleep
noot Jun 9, 2021
480b57d
increase test timeout in makefile
noot Jun 9, 2021
146813f
skip stalling test
noot Jun 9, 2021
c2a1d66
add type switch to check for grandpa message handler return
noot Jun 9, 2021
7059b87
lint
noot Jun 9, 2021
d871223
merge w development
noot Jun 9, 2021
b6ca72b
cleanup
noot Jun 9, 2021
c1f6961
merge w development
noot Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ VERSION=latest
endif
FULLDOCKERNAME=$(COMPANY)/$(NAME):$(VERSION)

.PHONY: help lint test install build clean start docker gossamer
.PHONY: help lint test install build clean start docker gossamer build-debug
all: help
help: Makefile
@echo
Expand Down Expand Up @@ -83,9 +83,8 @@ build:
GOBIN=$(PWD)/bin go run scripts/ci.go install

## debug: Builds application binary with debug flags and stores it in `./bin/gossamer`
build-debug:
@echo " > \033[32mBuilding binary...\033[0m "
GOBIN=$(PWD)/bin go run scripts/ci.go install-debug
build-debug: clean
cd cmd/gossamer && go build -gcflags=all="-N -l" -o ../../bin/gossamer && cd ../..

## init: Initialise gossamer using the default genesis and toml configuration files
init:
Expand Down
5 changes: 2 additions & 3 deletions dot/network/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type handshakeReader struct {
type notificationsProtocol struct {
protocolID protocol.ID
getHandshake HandshakeGetter
handshakeDecoder HandshakeDecoder
handshakeValidator HandshakeValidator

inboundHandshakeData *sync.Map //map[peer.ID]*handshakeData
Expand Down Expand Up @@ -207,7 +208,6 @@ func (s *Service) createNotificationsMessageHandler(info *notificationsProtocol,

func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtocol, msg NotificationsMessage) {
if support, err := s.host.supportsProtocol(peer, info.protocolID); err != nil || !support {
logger.Debug("the peer does not supports the protocol", "protocol", info.protocolID, "peer", peer, "err", err)
return
}

Expand Down Expand Up @@ -248,12 +248,11 @@ func (s *Service) sendData(peer peer.ID, hs Handshake, info *notificationsProtoc
_ = stream.Close()
info.outboundHandshakeData.Delete(peer)
return
case hsResponse := <-s.readHandshake(stream, decodeBlockAnnounceHandshake):
case hsResponse := <-s.readHandshake(stream, info.handshakeDecoder):
hsTimer.Stop()
if hsResponse.err != nil {
logger.Trace("failed to read handshake", "protocol", info.protocolID, "peer", peer, "error", err)
_ = stream.Close()

info.outboundHandshakeData.Delete(peer)
return
}
Expand Down
1 change: 1 addition & 0 deletions dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func (s *Service) RegisterNotificationsProtocol(sub protocol.ID,
protocolID: protocolID,
getHandshake: handshakeGetter,
handshakeValidator: handshakeValidator,
handshakeDecoder: handshakeDecoder,
inboundHandshakeData: new(sync.Map),
outboundHandshakeData: new(sync.Map),
}
Expand Down
11 changes: 0 additions & 11 deletions dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,6 @@ func (bs *BlockState) GetFinalizedHeader(round, setID uint64) (*types.Header, er

// GetFinalizedHash gets the latest finalised block header
func (bs *BlockState) GetFinalizedHash(round, setID uint64) (common.Hash, error) {
// get current round
r, err := bs.GetRound()
if err != nil {
return common.Hash{}, err
}

// round that is being queried for has not yet finalised
if round > r {
return common.Hash{}, fmt.Errorf("round not yet finalised")
}

h, err := bs.db.Get(finalizedHashKey(round, setID))
if err != nil {
return common.Hash{}, err
Expand Down
3 changes: 1 addition & 2 deletions lib/babe/babe.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,7 @@ func (b *Service) handleSlot(slotNum uint64) error {

block, err := b.buildBlock(parent, currentSlot)
if err != nil {
logger.Error("block authoring", "error", err)
return nil
return err
}

err = b.storageState.StoreTrie(ts)
Expand Down
4 changes: 4 additions & 0 deletions lib/grandpa/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@ func (s *Service) attemptToFinalize() error {
return ErrServicePaused
}

if s.ctx.Err() != nil {
return nil
}

has, _ := s.blockState.HasFinalizedBlock(s.state.round, s.state.setID)
if has {
return nil // a block was finalised, seems like we missed some messages
Expand Down
52 changes: 5 additions & 47 deletions lib/grandpa/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (h *MessageHandler) handleMessage(from peer.ID, m GrandpaMessage) (network.
// send vote message to grandpa service
h.grandpa.in <- vm
}
return nil, nil
case commitType:
if fm, ok := m.(*CommitMessage); ok {
return h.handleCommitMessage(fm)
Expand Down Expand Up @@ -85,7 +86,7 @@ func (h *MessageHandler) handleMessage(from peer.ID, m GrandpaMessage) (network.
}

func (h *MessageHandler) handleNeighbourMessage(from peer.ID, msg *NeighbourMessage) error {
currFinalized, err := h.grandpa.blockState.GetFinalizedHeader(0, 0)
currFinalized, err := h.blockState.GetFinalizedHeader(0, 0)
if err != nil {
return err
}
Expand All @@ -97,7 +98,7 @@ func (h *MessageHandler) handleNeighbourMessage(from peer.ID, msg *NeighbourMess

// TODO; determine if there is some reason we don't receive justifications in responses near the head (usually),
// and remove the following code if it's fixed.
head, err := h.grandpa.blockState.BestBlockNumber()
head, err := h.blockState.BestBlockNumber()
if err != nil {
return err
}
Expand Down Expand Up @@ -136,7 +137,7 @@ func (h *MessageHandler) handleNeighbourMessage(from peer.ID, msg *NeighbourMess
}

func (h *MessageHandler) handleCommitMessage(msg *CommitMessage) (*ConsensusMessage, error) {
logger.Debug("received finalisation message", "round", msg.Round, "hash", msg.Vote.hash)
logger.Debug("received finalisation message", "msg", msg)

if has, _ := h.blockState.HasFinalizedBlock(msg.Round, h.grandpa.state.setID); has {
return nil, nil
Expand Down Expand Up @@ -259,49 +260,6 @@ func (h *MessageHandler) verifyCatchUpResponseCompletability(prevote, precommit
return nil
}

// decodeMessage decodes a network-level consensus message into a GRANDPA VoteMessage or CommitMessage
func decodeMessage(msg *ConsensusMessage) (m GrandpaMessage, err error) {
var (
mi interface{}
ok bool
)

switch msg.Data[0] {
case voteType:
m = &VoteMessage{}
_, err = scale.Decode(msg.Data[1:], m)
case commitType:
r := &bytes.Buffer{}
_, _ = r.Write(msg.Data[1:])
cm := &CommitMessage{}
err = cm.Decode(r)
m = cm
case neighbourType:
mi, err = scale.Decode(msg.Data[1:], &NeighbourMessage{})
if m, ok = mi.(*NeighbourMessage); !ok {
return nil, ErrInvalidMessageType
}
case catchUpRequestType:
mi, err = scale.Decode(msg.Data[1:], &catchUpRequest{})
if m, ok = mi.(*catchUpRequest); !ok {
return nil, ErrInvalidMessageType
}
case catchUpResponseType:
mi, err = scale.Decode(msg.Data[1:], &catchUpResponse{})
if m, ok = mi.(*catchUpResponse); !ok {
return nil, ErrInvalidMessageType
}
default:
return nil, ErrInvalidMessageType
}

if err != nil {
return nil, err
}

return m, nil
}

func (h *MessageHandler) verifyCommitMessageJustification(fm *CommitMessage) error {
if len(fm.Precommits) != len(fm.AuthData) {
return ErrPrecommitSignatureMismatch
Expand All @@ -327,7 +285,7 @@ func (h *MessageHandler) verifyCommitMessageJustification(fm *CommitMessage) err

// confirm total # signatures >= grandpa threshold
if uint64(count) < h.grandpa.state.threshold() {
logger.Error("minimum votes not met for finalisation message", "votes needed", h.grandpa.state.threshold(),
logger.Debug("minimum votes not met for finalisation message", "votes needed", h.grandpa.state.threshold(),
"votes received", len(fm.Precommits))
return ErrMinVotesNotMet
}
Expand Down
58 changes: 53 additions & 5 deletions lib/grandpa/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package grandpa

import (
"bytes"
"fmt"
"time"

Expand Down Expand Up @@ -136,7 +137,6 @@ func (s *Service) decodeMessage(in []byte) (NotificationsMessage, error) {

func (s *Service) handleNetworkMessage(from peer.ID, msg NotificationsMessage) (bool, error) {
if msg == nil {
logger.Trace("received nil message, ignoring")
return false, nil
}

Expand All @@ -145,8 +145,7 @@ func (s *Service) handleNetworkMessage(from peer.ID, msg NotificationsMessage) (
return false, ErrInvalidMessageType
}

if len(cm.Data) == 0 {
logger.Trace("received message with nil data, ignoring")
if len(cm.Data) < 2 {
return false, nil
}

Expand All @@ -160,8 +159,14 @@ func (s *Service) handleNetworkMessage(from peer.ID, msg NotificationsMessage) (
return false, err
}

if resp != nil {
s.network.SendMessage(resp)
switch r := resp.(type) {
case *ConsensusMessage:
if r != nil {
s.network.SendMessage(resp)
}
case nil:
default:
logger.Warn("unexpected type returned from message handler", "response", resp)
}

if m.Type() == neighbourType || m.Type() == catchUpResponseType {
Expand Down Expand Up @@ -203,3 +208,46 @@ func (s *Service) sendNeighbourMessage() {
s.network.SendMessage(cm)
}
}

// decodeMessage decodes a network-level consensus message into a GRANDPA VoteMessage or CommitMessage
func decodeMessage(msg *ConsensusMessage) (m GrandpaMessage, err error) {
var (
mi interface{}
ok bool
)

switch msg.Data[0] {
case voteType:
m = &VoteMessage{}
_, err = scale.Decode(msg.Data[1:], m)
case commitType:
r := &bytes.Buffer{}
_, _ = r.Write(msg.Data[1:])
cm := &CommitMessage{}
err = cm.Decode(r)
m = cm
case neighbourType:
mi, err = scale.Decode(msg.Data[1:], &NeighbourMessage{})
if m, ok = mi.(*NeighbourMessage); !ok {
return nil, ErrInvalidMessageType
}
case catchUpRequestType:
mi, err = scale.Decode(msg.Data[1:], &catchUpRequest{})
if m, ok = mi.(*catchUpRequest); !ok {
return nil, ErrInvalidMessageType
}
case catchUpResponseType:
mi, err = scale.Decode(msg.Data[1:], &catchUpResponse{})
if m, ok = mi.(*catchUpResponse); !ok {
return nil, ErrInvalidMessageType
}
default:
return nil, ErrInvalidMessageType
}

if err != nil {
return nil, err
}

return m, nil
}
9 changes: 7 additions & 2 deletions lib/grandpa/vote_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (s *Service) receiveMessages(cond func() bool) {
logger.Trace("received vote message", "msg", msg)
vm, ok := msg.(*VoteMessage)
if !ok {
logger.Trace("failed to cast message to VoteMessage")
continue
}

Expand All @@ -52,7 +51,13 @@ func (s *Service) receiveMessages(cond func() bool) {
continue
}

logger.Debug("validated vote message", "vote", v, "round", vm.Round, "subround", vm.Message.Stage, "precommits", s.precommits)
logger.Debug("validated vote message",
"vote", v,
"round", vm.Round,
"subround", vm.Message.Stage,
"prevotes", s.prevotes,
"precommits", s.precommits,
)
case <-ctx.Done():
logger.Trace("returning from receiveMessages")
return
Expand Down