Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 5 additions & 6 deletions dot/parachain/bitfield-distribution/bitfield_distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"fmt"
"sync"

"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/runtime"

networkbridge "github.com/ChainSafe/gossamer/dot/parachain/network-bridge"
Expand Down Expand Up @@ -265,21 +264,21 @@
prevNeighbors := b.topologies.CurrentTopology.LocalNeighbours

peers := make(map[peer.ID]struct{})
for _, val := range newTopology.PeerIDs {
for val := range newTopology.Peers {
peers[val] = struct{}{}
}

shuffledIndices := make([]uint, len(event.Topology.ShuffledIndices))
for i, v := range event.Topology.ShuffledIndices {
shuffledIndices[i] = uint(v)

Check failure on line 273 in dot/parachain/bitfield-distribution/bitfield_distribution.go

View workflow job for this annotation

GitHub Actions / linting

unnecessary conversion (unconvert)
}

canonicalShuffling := make([]grid.TopologyPeerInfo, len(event.Topology.CanonicalShuffling))
for i, info := range event.Topology.CanonicalShuffling {
t := grid.TopologyPeerInfo{
Peers: info.PeerID,
Peers: info.Peers,
ValidatorIndex: info.ValidatorIndex,
DiscoveryID: types.AuthorityID(info.DiscoveryID),
DiscoveryID: parachaintypes.AuthorityDiscoveryID(info.DiscoveryID),

Check failure on line 281 in dot/parachain/bitfield-distribution/bitfield_distribution.go

View workflow job for this annotation

GitHub Actions / linting

unnecessary conversion (unconvert)
}
canonicalShuffling[i] = t
}
Expand Down Expand Up @@ -493,9 +492,9 @@
func (b *BitfieldDistribution) processUpdatedAuthorityIDsEvent(event networkbridgeevents.UpdatedAuthorityIDs) error {
logger.Tracef("process UpdatedAuthorityIDs event: %v", event)

ids := make(map[types.AuthorityID]struct{})
ids := make(map[parachaintypes.AuthorityDiscoveryID]struct{})
for _, id := range event.AuthorityDiscoveryIDs {
ids[types.AuthorityID(id)] = struct{}{}
ids[parachaintypes.AuthorityDiscoveryID(id)] = struct{}{}

Check failure on line 497 in dot/parachain/bitfield-distribution/bitfield_distribution.go

View workflow job for this annotation

GitHub Actions / linting

unnecessary conversion (unconvert)
}
ok, err := b.topologies.CurrentTopology.UpdateAuthoritiesIDs(event.PeerID, ids)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/dot/parachain/util"
validationprotocol "github.com/ChainSafe/gossamer/dot/parachain/validation-protocol"
"github.com/ChainSafe/gossamer/dot/types"
"github.com/ChainSafe/gossamer/lib/common"
"github.com/ChainSafe/gossamer/lib/crypto/sr25519"
"github.com/ChainSafe/gossamer/lib/keystore"
Expand Down Expand Up @@ -627,7 +626,7 @@ func TestBitfieldDistribution_ProcessBitfieldDistributionMessage_CheckSignedAvai
gt := grid.NewSessionGridTopology([]uint{1, 2, 3}, []grid.TopologyPeerInfo{{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{1},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{1},
}})
sgte := &grid.SessionGridTopologyEntry{
Topology: gt,
Expand Down Expand Up @@ -1204,7 +1203,7 @@ func TestBitfieldDistribution_ProcessIncomingPeerMessageEvent_Success(t *testing
gt := grid.NewSessionGridTopology([]uint{1, 2, 3}, []grid.TopologyPeerInfo{{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{1},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{1},
}})
sgte := &grid.SessionGridTopologyEntry{
Topology: gt,
Expand Down Expand Up @@ -1607,7 +1606,7 @@ func TestBitfieldDistribution_processUpdatedAuthorityIDsEvent(t *testing.T) {
gt := grid.NewSessionGridTopology([]uint{1}, []grid.TopologyPeerInfo{{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{2},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{2},
},
})
assert.Len(t, gt.Peers, 2)
Expand Down
4 changes: 2 additions & 2 deletions dot/parachain/gossip-support/gossip_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (gs *GossipSupport) updateGossipTopology(
) error {
authLen := len(authorities)
canonicalShuffling := make([]networkbridgeevents.CanonicalShuffling, authLen)
shuffledIndices := make([]uint8, authLen)
shuffledIndices := make([]uint, authLen)

for i, a := range authorities {
canonicalShuffling[i] = networkbridgeevents.CanonicalShuffling{AuthorityDiscoveryID: a,
Expand All @@ -468,7 +468,7 @@ func (gs *GossipSupport) updateGossipTopology(
}

for i, pair := range canonicalShuffling {
shuffledIndices[int(pair.ValidatorIndex)] = uint8(i)
shuffledIndices[int(pair.ValidatorIndex)] = uint(i)
}

localIndex := parachaintypes.ValidatorIndex(ourIndex)
Expand Down
7 changes: 3 additions & 4 deletions dot/parachain/grid/grid_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math"

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/dot/types"

"github.com/libp2p/go-libp2p/core/peer"
)
Expand All @@ -18,7 +17,7 @@ type TopologyPeerInfo struct {
// This can extend _beyond_ the set of active parachain validators.
ValidatorIndex parachaintypes.ValidatorIndex
// DiscoveryID is the authority discovery public key of the validator in the corresponding `SessionInfo`.
DiscoveryID types.AuthorityID
DiscoveryID parachaintypes.AuthorityDiscoveryID
}

// SessionGridTopology is topology representation for session
Expand Down Expand Up @@ -54,7 +53,7 @@ func NewSessionGridTopology(shuffledIndices []uint, canonicalShuffling []Topolog
// hence there could be multiple AuthorityID associated with a peerID.
// Updates Peers hashset with new peer id if the peer is in the grid topology.
// Returns true if the peer is in the grid topology.
func (gt *SessionGridTopology) UpdateAuthoritiesIDs(peer peer.ID, discoveryIDs map[types.AuthorityID]struct{}) bool {
func (gt *SessionGridTopology) UpdateAuthoritiesIDs(peer peer.ID, discoveryIDs map[parachaintypes.AuthorityDiscoveryID]struct{}) bool {
updated := false
if _, ok := gt.Peers[peer]; !ok {
for i := range gt.CanonicalShuffling {
Expand Down Expand Up @@ -295,7 +294,7 @@ func (s *SessionGridTopologyEntry) PeersToRoute(routing RequiredRouting) []peer.

func (s *SessionGridTopologyEntry) UpdateAuthoritiesIDs(
peer peer.ID,
discoveryIDs map[types.AuthorityID]struct{}) (bool, error) {
discoveryIDs map[parachaintypes.AuthorityDiscoveryID]struct{}) (bool, error) {
if s.Topology.UpdateAuthoritiesIDs(peer, discoveryIDs) {
// If authorities update, recompile neighbours
new_neighbours, err := s.Topology.ComputeGridNeighboursFor(s.LocalIndex)
Expand Down
33 changes: 16 additions & 17 deletions dot/parachain/grid/grid_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
"github.com/ChainSafe/gossamer/dot/types"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/stretchr/testify/assert"
Expand All @@ -16,57 +15,57 @@ func FixtureTopologyPeerInfo() []TopologyPeerInfo {
{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(0),
DiscoveryID: types.AuthorityID{1},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{1},
},
{
Peers: []peer.ID{"peer3", "peer4"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{2},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{2},
},
{
Peers: []peer.ID{"peer5", "peer6"},
ValidatorIndex: parachaintypes.ValidatorIndex(2),
DiscoveryID: types.AuthorityID{3},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{3},
},
{
Peers: []peer.ID{"peer7", "peer8"},
ValidatorIndex: parachaintypes.ValidatorIndex(3),
DiscoveryID: types.AuthorityID{4},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{4},
},
{
Peers: []peer.ID{"peer9", "peer10"},
ValidatorIndex: parachaintypes.ValidatorIndex(4),
DiscoveryID: types.AuthorityID{5},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{5},
},
{
Peers: []peer.ID{"peer11", "peer12"},
ValidatorIndex: parachaintypes.ValidatorIndex(5),
DiscoveryID: types.AuthorityID{6},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{6},
},
{
Peers: []peer.ID{"peer13", "peer14"},
ValidatorIndex: parachaintypes.ValidatorIndex(6),
DiscoveryID: types.AuthorityID{7},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{7},
},
{
Peers: []peer.ID{"peer15", "peer16"},
ValidatorIndex: parachaintypes.ValidatorIndex(7),
DiscoveryID: types.AuthorityID{8},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{8},
},
{
Peers: []peer.ID{"peer17", "peer18"},
ValidatorIndex: parachaintypes.ValidatorIndex(8),
DiscoveryID: types.AuthorityID{9},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{9},
},
{
Peers: []peer.ID{"peer19", "peer20"},
ValidatorIndex: parachaintypes.ValidatorIndex(9),
DiscoveryID: types.AuthorityID{10},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{10},
},
{
Peers: []peer.ID{"peer21", "peer22"},
ValidatorIndex: parachaintypes.ValidatorIndex(10),
DiscoveryID: types.AuthorityID{11},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{11},
},
}
}
Expand All @@ -75,15 +74,15 @@ func Test_SessionGridTopology(t *testing.T) {
gt := NewSessionGridTopology([]uint{1, 2, 3}, []TopologyPeerInfo{{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{1},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{1},
},
})
assert.Len(t, gt.Peers, 2)

updated := gt.UpdateAuthoritiesIDs(peer.ID("peer2"), map[types.AuthorityID]struct{}{{1}: {}})
updated := gt.UpdateAuthoritiesIDs(peer.ID("peer2"), map[parachaintypes.AuthorityDiscoveryID]struct{}{{1}: {}})
assert.False(t, updated)

updated = gt.UpdateAuthoritiesIDs(peer.ID("peer3"), map[types.AuthorityID]struct{}{{1}: {}})
updated = gt.UpdateAuthoritiesIDs(peer.ID("peer3"), map[parachaintypes.AuthorityDiscoveryID]struct{}{{1}: {}})
assert.True(t, updated)
assert.Len(t, gt.Peers, 3)
assert.Equal(t,
Expand All @@ -96,7 +95,7 @@ func Test_SessionGridTopologyNeighbours(t *testing.T) {
gt := NewSessionGridTopology([]uint{1, 2, 3}, []TopologyPeerInfo{{
Peers: []peer.ID{"peer1", "peer2"},
ValidatorIndex: parachaintypes.ValidatorIndex(1),
DiscoveryID: types.AuthorityID{1},
DiscoveryID: parachaintypes.AuthorityDiscoveryID{1},
},
})
_, err := gt.ComputeGridNeighboursFor(1)
Expand Down Expand Up @@ -167,7 +166,7 @@ func Test_SessionGridTopologyEntry(t *testing.T) {
assert.Len(t, sgte.PeersToRoute(RequiredRoutingGridY), 6)
assert.Len(t, sgte.PeersToRoute(RequiredRoutingAll), 22)

updated, err := sgte.UpdateAuthoritiesIDs(peer.ID("peer99"), map[types.AuthorityID]struct{}{{10}: {}})
updated, err := sgte.UpdateAuthoritiesIDs(peer.ID("peer99"), map[parachaintypes.AuthorityDiscoveryID]struct{}{{10}: {}})
assert.True(t, updated)
assert.Nil(t, err)
// Now we added one more peer to validator with AuthorityID 10, index 9. Sine we are actins as validator with index 10
Expand Down
3 changes: 2 additions & 1 deletion dot/parachain/network-bridge/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package events

import (
collationprotocol "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
"github.com/ChainSafe/gossamer/dot/parachain/grid"
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types"
validationprotocol "github.com/ChainSafe/gossamer/dot/parachain/validation-protocol"

Expand Down Expand Up @@ -43,7 +44,7 @@ type CanonicalShuffling struct {

type NewGossipTopology struct {
Session parachaintypes.SessionIndex
Topology SessionGridTopology
Topology grid.SessionGridTopology
LocalIndex *parachaintypes.ValidatorIndex
}

Expand Down
33 changes: 0 additions & 33 deletions dot/parachain/network-bridge/events/grid_topology.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type NewGossipTopology struct {
CanonicalShuffling []events.CanonicalShuffling
// The reverse mapping of `canonical_shuffling`: from validator index
// to the index in `canonical_shuffling`
ShuffledIndices []uint8
ShuffledIndices []uint
}

// UpdateAuthorityIDs is used to inform the distribution subsystems about `AuthorityDiscoveryId` key rotations.
Expand Down
11 changes: 6 additions & 5 deletions dot/parachain/network-bridge/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ChainSafe/gossamer/dot/network"

collatorprotocolmessages "github.com/ChainSafe/gossamer/dot/parachain/collator-protocol/messages"
"github.com/ChainSafe/gossamer/dot/parachain/grid"
"github.com/ChainSafe/gossamer/dot/parachain/network-bridge/events"
networkbridgemessages "github.com/ChainSafe/gossamer/dot/parachain/network-bridge/messages"
validationprotocol "github.com/ChainSafe/gossamer/dot/parachain/validation-protocol"
Expand Down Expand Up @@ -373,7 +374,7 @@ func (nbr *NetworkBridgeReceiver) processMessage(msg any) error { //nolint

newGossipTopology := events.NewGossipTopology{
Session: msg.Session,
Topology: events.SessionGridTopology{
Topology: grid.SessionGridTopology{
ShuffledIndices: msg.ShuffledIndices,
CanonicalShuffling: peerTopologies,
},
Expand All @@ -395,14 +396,14 @@ func (nbr *NetworkBridgeReceiver) processMessage(msg any) error { //nolint
}

func getTopologyPeers(authorityDiscoveryService AuthorityDiscoveryService,
neighbours []events.CanonicalShuffling) []events.TopologyPeerInfo {
neighbours []events.CanonicalShuffling) []grid.TopologyPeerInfo {

peers := make([]events.TopologyPeerInfo, len(neighbours))
peers := make([]grid.TopologyPeerInfo, len(neighbours))

for _, neighbour := range neighbours {
peerID := authorityDiscoveryService.GetPeerIDByAuthorityID(neighbour.AuthorityDiscoveryID)
peers = append(peers, events.TopologyPeerInfo{
PeerID: []peer.ID{peerID},
peers = append(peers, grid.TopologyPeerInfo{
Peers: peer.IDSlice{peerID},
ValidatorIndex: neighbour.ValidatorIndex,
DiscoveryID: neighbour.AuthorityDiscoveryID,
})
Expand Down
Loading
Loading