Skip to content

Commit

Permalink
use generic set (#391)
Browse files Browse the repository at this point in the history
* use generic set

* bump version

* nit

* update inner go mod

* Bump rpcchainvm version in compatibility.json

Co-authored-by: aaronbuchwald <aaron.buchwald56@gmail.com>
Co-authored-by: Stephen <stephen@avalabs.org>
  • Loading branch information
3 people committed Dec 7, 2022
1 parent c002776 commit 1ea66a9
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/simulator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ replace github.com/ava-labs/subnet-evm => ../..

require (
github.com/VictoriaMetrics/fastcache v1.10.0 // indirect
github.com/ava-labs/avalanchego v1.9.3 // indirect
github.com/ava-labs/avalanchego v1.9.4-rc.11 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/simulator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/ava-labs/avalanchego v1.9.3 h1:vEIa5R7p9P+q1Tf4DHFQppI0ELgKdv0tLVx4sMDNXZc=
github.com/ava-labs/avalanchego v1.9.3/go.mod h1:UR0FdZiS5+0fEqGk3S8zLIiQ2xdzIfTcCnndBRJQ5NA=
github.com/ava-labs/avalanchego v1.9.4-rc.11 h1:wXu4u/XexkiIQPxUYWkJ6M7kCNUTwoKDOUAsqX/dbms=
github.com/ava-labs/avalanchego v1.9.4-rc.11/go.mod h1:H4pMTYzgudfPs9WX+KXI0nCiUGNkdgPWOwm1nqzGibQ=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
2 changes: 1 addition & 1 deletion compatibility.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"rpcChainVMProtocolVersion": {
"v0.4.5": 19,
"v0.4.5": 20,
"v0.4.4": 19,
"v0.4.3": 19,
"v0.4.2": 18,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0
github.com/ava-labs/avalanchego v1.9.3
github.com/ava-labs/avalanchego v1.9.4-rc.11
github.com/cespare/cp v0.1.0
github.com/creack/pty v1.1.18
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
github.com/apache/arrow/go/arrow v0.0.0-20191024131854-af6fa24be0db/go.mod h1:VTxUBvSJ3s3eHAg65PNgrsn5BtqCRPdmyXh6rAfdxN0=
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0 h1:TVi9JEdKNU/RevYZ9PyW4pULbEdS+KQDA9Ki2DUvuAs=
github.com/ava-labs/avalanche-network-runner-sdk v0.3.0/go.mod h1:SgKJvtqvgo/Bl/c8fxEHCLaSxEbzimYfBopcfrajxQk=
github.com/ava-labs/avalanchego v1.9.3 h1:vEIa5R7p9P+q1Tf4DHFQppI0ELgKdv0tLVx4sMDNXZc=
github.com/ava-labs/avalanchego v1.9.3/go.mod h1:UR0FdZiS5+0fEqGk3S8zLIiQ2xdzIfTcCnndBRJQ5NA=
github.com/ava-labs/avalanchego v1.9.4-rc.11 h1:wXu4u/XexkiIQPxUYWkJ6M7kCNUTwoKDOUAsqX/dbms=
github.com/ava-labs/avalanchego v1.9.4-rc.11/go.mod h1:H4pMTYzgudfPs9WX+KXI0nCiUGNkdgPWOwm1nqzGibQ=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down
3 changes: 2 additions & 1 deletion peer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/version"

"github.com/ava-labs/subnet-evm/peer/stats"
Expand Down Expand Up @@ -153,7 +154,7 @@ func (n *network) request(nodeID ids.NodeID, request []byte, responseHandler mes

n.outstandingRequestHandlers[requestID] = responseHandler

nodeIDs := ids.NewNodeIDSet(1)
nodeIDs := set.NewSet[ids.NodeID](1)
nodeIDs.Add(nodeID)

// send app request to the peer
Expand Down
15 changes: 8 additions & 7 deletions peer/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/set"

"github.com/ava-labs/subnet-evm/plugin/evm/message"

Expand Down Expand Up @@ -56,7 +57,7 @@ func TestRequestAnyRequestsRoutingAndResponse(t *testing.T) {
senderWg := &sync.WaitGroup{}
var net Network
sender := testAppSender{
sendAppRequestFn: func(nodes ids.NodeIDSet, requestID uint32, requestBytes []byte) error {
sendAppRequestFn: func(nodes set.Set[ids.NodeID], requestID uint32, requestBytes []byte) error {
nodeID, _ := nodes.Pop()
senderWg.Add(1)
go func() {
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestRequestRequestsRoutingAndResponse(t *testing.T) {
var lock sync.Mutex
contactedNodes := make(map[ids.NodeID]struct{})
sender := testAppSender{
sendAppRequestFn: func(nodes ids.NodeIDSet, requestID uint32, requestBytes []byte) error {
sendAppRequestFn: func(nodes set.Set[ids.NodeID], requestID uint32, requestBytes []byte) error {
nodeID, _ := nodes.Pop()
lock.Lock()
contactedNodes[nodeID] = struct{}{}
Expand Down Expand Up @@ -221,7 +222,7 @@ func TestRequestMinVersion(t *testing.T) {

var net Network
sender := testAppSender{
sendAppRequestFn: func(nodes ids.NodeIDSet, reqID uint32, messageBytes []byte) error {
sendAppRequestFn: func(nodes set.Set[ids.NodeID], reqID uint32, messageBytes []byte) error {
atomic.AddUint32(&callNum, 1)
assert.True(t, nodes.Contains(nodeID), "request nodes should contain expected nodeID")
assert.Len(t, nodes, 1, "request nodes should contain exactly one node")
Expand Down Expand Up @@ -285,7 +286,7 @@ func TestOnRequestHonoursDeadline(t *testing.T) {
var net Network
responded := false
sender := testAppSender{
sendAppRequestFn: func(nodes ids.NodeIDSet, reqID uint32, message []byte) error {
sendAppRequestFn: func(nodes set.Set[ids.NodeID], reqID uint32, message []byte) error {
return nil
},
sendAppResponseFn: func(nodeID ids.NodeID, reqID uint32, message []byte) error {
Expand Down Expand Up @@ -455,7 +456,7 @@ func buildGossip(codec codec.Manager, msg message.GossipMessage) ([]byte, error)
type testAppSender struct {
sendCrossChainAppRequestFn func(ids.ID, uint32, []byte) error
sendCrossChainAppResponseFn func(ids.ID, uint32, []byte) error
sendAppRequestFn func(ids.NodeIDSet, uint32, []byte) error
sendAppRequestFn func(set.Set[ids.NodeID], uint32, []byte) error
sendAppResponseFn func(ids.NodeID, uint32, []byte) error
sendAppGossipFn func([]byte) error
}
Expand All @@ -468,11 +469,11 @@ func (t testAppSender) SendCrossChainAppResponse(_ context.Context, chainID ids.
return t.sendCrossChainAppResponseFn(chainID, requestID, appResponseBytes)
}

func (t testAppSender) SendAppGossipSpecific(context.Context, ids.NodeIDSet, []byte) error {
func (t testAppSender) SendAppGossipSpecific(context.Context, set.Set[ids.NodeID], []byte) error {
panic("not implemented")
}

func (t testAppSender) SendAppRequest(_ context.Context, nodeIDs ids.NodeIDSet, requestID uint32, message []byte) error {
func (t testAppSender) SendAppRequest(_ context.Context, nodeIDs set.Set[ids.NodeID], requestID uint32, message []byte) error {
return t.sendAppRequestFn(nodeIDs, requestID, message)
}

Expand Down
9 changes: 5 additions & 4 deletions peer/peer_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
utils_math "github.com/ava-labs/avalanchego/utils/math"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/version"

"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -43,9 +44,9 @@ type peerInfo struct {
type peerTracker struct {
peers map[ids.NodeID]*peerInfo // all peers we are connected to
numTrackedPeers metrics.Gauge
trackedPeers ids.NodeIDSet // peers that we have sent a request to
trackedPeers set.Set[ids.NodeID] // peers that we have sent a request to
numResponsivePeers metrics.Gauge
responsivePeers ids.NodeIDSet // peers that responded to the last request they were sent
responsivePeers set.Set[ids.NodeID] // peers that responded to the last request they were sent
bandwidthHeap utils_math.AveragerHeap // tracks bandwidth peers are responding with
averageBandwidthMetric metrics.GaugeFloat64
averageBandwidth utils_math.Averager
Expand All @@ -55,9 +56,9 @@ func NewPeerTracker() *peerTracker {
return &peerTracker{
peers: make(map[ids.NodeID]*peerInfo),
numTrackedPeers: metrics.GetOrRegisterGauge("net_tracked_peers", nil),
trackedPeers: make(ids.NodeIDSet),
trackedPeers: make(set.Set[ids.NodeID]),
numResponsivePeers: metrics.GetOrRegisterGauge("net_responsive_peers", nil),
responsivePeers: make(ids.NodeIDSet),
responsivePeers: make(set.Set[ids.NodeID]),
bandwidthHeap: utils_math.NewMaxAveragerHeap(),
averageBandwidthMetric: metrics.GetOrRegisterGaugeFloat64("net_average_bandwidth", nil),
averageBandwidth: utils_math.NewAverager(0, bandwidthHalflife, time.Now()),
Expand Down
5 changes: 3 additions & 2 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/choices"
commonEng "github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/set"

"github.com/ava-labs/subnet-evm/accounts/keystore"
"github.com/ava-labs/subnet-evm/consensus/dummy"
Expand Down Expand Up @@ -113,7 +114,7 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
syncDisabledVM := &VM{}
appSender := &commonEng.SenderTest{T: t}
appSender.SendAppGossipF = func(context.Context, []byte) error { return nil }
appSender.SendAppRequestF = func(ctx context.Context, nodeSet ids.NodeIDSet, requestID uint32, request []byte) error {
appSender.SendAppRequestF = func(ctx context.Context, nodeSet set.Set[ids.NodeID], requestID uint32, request []byte) error {
nodeID, hasItem := nodeSet.Pop()
if !hasItem {
t.Fatal("expected nodeSet to contain at least 1 nodeID")
Expand Down Expand Up @@ -315,7 +316,7 @@ func createSyncServerAndClientVMs(t *testing.T, test syncTest) *syncVMSetup {
))

// override [syncerVM]'s SendAppRequest function to trigger AppRequest on [serverVM]
syncerAppSender.SendAppRequestF = func(ctx context.Context, nodeSet ids.NodeIDSet, requestID uint32, request []byte) error {
syncerAppSender.SendAppRequestF = func(ctx context.Context, nodeSet set.Set[ids.NodeID], requestID uint32, request []byte) error {
nodeID, hasItem := nodeSet.Pop()
if !hasItem {
t.Fatal("expected nodeSet to contain at least 1 nodeID")
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/tx_gossiping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestMempoolTxsAppGossipHandling(t *testing.T) {
txRequested bool
)
sender.CantSendAppGossip = false
sender.SendAppRequestF = func(context.Context, ids.NodeIDSet, uint32, []byte) error {
sender.SendAppRequestF = func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
txRequested = true
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Set up the versions to be used
subnet_evm_version=${SUBNET_EVM_VERSION:-'v0.4.4'}
# Don't export them as they're used in the context of other calls
avalanche_version=${AVALANCHE_VERSION:-'v1.9.3'}
avalanche_version=${AVALANCHE_VERSION:-'v1.9.4-rc.11'}
network_runner_version=${NETWORK_RUNNER_VERSION:-'35be10cd3867a94fbe960a1c14a455f179de60d9'}
ginkgo_version=${GINKGO_VERSION:-'v2.2.0'}

Expand Down
5 changes: 3 additions & 2 deletions sync/statesync/code_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/subnet-evm/core/rawdb"
"github.com/ava-labs/subnet-evm/ethdb"
"github.com/ava-labs/subnet-evm/plugin/evm/message"
Expand Down Expand Up @@ -46,7 +47,7 @@ type codeSyncer struct {

CodeSyncerConfig

outstandingCodeHashes ids.Set // Set of code hashes that we need to fetch from the network.
outstandingCodeHashes set.Set[ids.ID] // Set of code hashes that we need to fetch from the network.
codeHashes chan common.Hash // Channel of incoming code hash requests

// Used to set terminal error or pass nil to [errChan] if successful.
Expand All @@ -63,7 +64,7 @@ func newCodeSyncer(config CodeSyncerConfig) *codeSyncer {
return &codeSyncer{
CodeSyncerConfig: config,
codeHashes: make(chan common.Hash, config.MaxOutstandingCodeHashes),
outstandingCodeHashes: ids.NewSet(0),
outstandingCodeHashes: set.NewSet[ids.ID](0),
errChan: make(chan error, 1),
}
}
Expand Down

0 comments on commit 1ea66a9

Please sign in to comment.