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

Use SDK Gossip #318

Merged
merged 37 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2fdd559
evm gossip
joshua-kim Jun 6, 2023
ca37577
nit
joshua-kim Sep 6, 2023
c93ee73
Update plugin/evm/gossip_mempool.go
joshua-kim Sep 8, 2023
bb513d6
nits
joshua-kim Sep 8, 2023
cdb9649
nit
joshua-kim Sep 8, 2023
33b8a06
nit
joshua-kim Sep 8, 2023
845b93d
nit
joshua-kim Sep 8, 2023
76cc2d2
Update plugin/evm/gossip_mempool.go
joshua-kim Sep 8, 2023
954f60f
Update plugin/evm/gossip_mempool.go
joshua-kim Sep 8, 2023
c83364f
Update plugin/evm/mempool.go
joshua-kim Sep 8, 2023
021f8bf
try go 1.20
joshua-kim Sep 8, 2023
8c56141
Revert "try go 1.20"
joshua-kim Sep 8, 2023
90398eb
Update plugin/evm/gossip_mempool.go
joshua-kim Sep 8, 2023
673f5ab
clean mod cache
joshua-kim Sep 8, 2023
234bdb1
Revert "clean mod cache"
joshua-kim Sep 8, 2023
61a1c16
version
joshua-kim Sep 8, 2023
2898ee5
nits
joshua-kim Sep 8, 2023
248a1ca
nit
joshua-kim Sep 8, 2023
0393cfb
nit
joshua-kim Sep 11, 2023
474a03c
nit
joshua-kim Sep 11, 2023
844ccd2
nit
joshua-kim Sep 11, 2023
db51063
nits
joshua-kim Sep 11, 2023
fbfa372
nit
joshua-kim Sep 11, 2023
ec525c9
nit
joshua-kim Sep 11, 2023
25d0bf3
fix ci
joshua-kim Sep 11, 2023
78698af
fix docker version
joshua-kim Sep 11, 2023
6d8f21e
nit
joshua-kim Sep 11, 2023
d4b722c
update go version in ci
joshua-kim Sep 11, 2023
2094e8d
nit
joshua-kim Sep 11, 2023
fe04ca8
nit
joshua-kim Sep 12, 2023
678f640
Squashed commit of the following:
joshua-kim Sep 12, 2023
d487de1
remove ctx field
joshua-kim Sep 12, 2023
0c5a462
add nil check
joshua-kim Sep 12, 2023
0e34744
oops
joshua-kim Sep 12, 2023
461170e
nit
joshua-kim Sep 12, 2023
5a9a7e7
Squashed commit of the following:
joshua-kim Sep 12, 2023
1ffc8e2
Merge branch 'master' into sdk-gossip
joshua-kim Sep 12, 2023
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v3
with:
go-version: '~1.19.12'
go-version: '~1.20.8'
joshua-kim marked this conversation as resolved.
Show resolved Hide resolved
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v3
with:
go-version: '~1.19.12'
go-version: '~1.20.8'
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v3
with:
go-version: '~1.19.12'
go-version: '~1.20.8'
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v3
with:
go-version: '~1.19.12'
go-version: '~1.20.8'
check-latest: true
- name: change avalanchego dep
if: ${{ github.event_name == 'workflow_dispatch' }}
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
token: ${{ secrets.AVALANCHE_PAT }}
- uses: actions/setup-go@v3
with:
go-version: '~1.19.12'
go-version: '~1.20.8'
check-latest: true
- name: Run e2e tests
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.19.12-bullseye AS builder
FROM golang:1.20.8-bullseye AS builder

ARG AVALANCHE_VERSION

Expand All @@ -17,7 +17,7 @@ WORKDIR $GOPATH/src/github.com/ava-labs/avalanchego
RUN go mod download
# Replace the coreth dependency
RUN go mod edit -replace github.com/ava-labs/coreth=../coreth
RUN go mod download && go mod tidy -compat=1.19
RUN go mod download && go mod tidy -compat=1.20

# Build the AvalancheGo binary with local version of coreth.
RUN ./scripts/build_avalanche.sh
Expand Down
15 changes: 15 additions & 0 deletions core/txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,21 @@ func (pool *TxPool) PendingSize() int {
return count
}

// IteratePending iterates over [pool.pending] until [f] returns false.
// The caller must not modify [tx].
func (pool *TxPool) IteratePending(f func(tx *types.Transaction) bool) {
pool.mu.RLock()
defer pool.mu.RUnlock()

for _, list := range pool.pending {
for _, tx := range list.txs.items {
if !f(tx) {
return
}
}
}
Comment on lines +639 to +645
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to prioritize transactions by nonce or perhaps local addresses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending and items are both maps which have random-ish iteration orders so I'm not super concerned about starvation but it could be a good follow-up

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, the other concern would be if we end up sending only transactions with future nonces and don't include the necessary transaction to make them executable. This is an edge case when we hit the max size, so I don't think this needs to block the PR.

}

// Locals retrieves the accounts currently considered local by the pool.
func (pool *TxPool) Locals() []common.Address {
pool.mu.Lock()
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/ava-labs/coreth

go 1.19
go 1.20

require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanchego v1.10.9-rc.4
github.com/ava-labs/avalanchego v1.10.10-rc.2
github.com/cespare/cp v0.1.0
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
github.com/davecgh/go-spew v1.1.1
Expand Down Expand Up @@ -38,12 +38,14 @@ require (
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
go.uber.org/goleak v1.2.1
go.uber.org/mock v0.2.0
golang.org/x/crypto v0.1.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/sync v0.1.0
golang.org/x/sys v0.8.0
golang.org/x/text v0.8.0
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
google.golang.org/protobuf v1.30.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

Expand Down Expand Up @@ -126,15 +128,13 @@ require (
go.opentelemetry.io/otel/trace v1.11.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/mock v0.2.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/term v0.7.0 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
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/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.10.9-rc.4 h1:vtavPfRiF6r1Zc6RV8/arEfVpe9GQsLWHbMfIWkHbMI=
github.com/ava-labs/avalanchego v1.10.9-rc.4/go.mod h1:vTBLl1zK36olfLRA7IUfdbvphWqlkuarIoXxvZTHZVw=
github.com/ava-labs/avalanchego v1.10.10-rc.1 h1:dPJISEWqL3tdUShe6RuB8CFuXl3rsH8617sXbLBjkIE=
github.com/ava-labs/avalanchego v1.10.10-rc.1/go.mod h1:C8R5uiltpc8MQ62ixxgODR+15mesWF0aAw3H+Qrl9Iw=
github.com/ava-labs/avalanchego v1.10.10-rc.2 h1:nlHc1JwKb5TEc9oqPU2exvOpazhxr11N2ym/LzYxv4k=
github.com/ava-labs/avalanchego v1.10.10-rc.2/go.mod h1:BN97sZppDSvIMIfEjrLTjdPTFkGLkb0ISJHEcoxMMNk=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down
29 changes: 15 additions & 14 deletions peer/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/prometheus/client_golang/prometheus"

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

Expand Down Expand Up @@ -57,7 +58,7 @@ var (

func TestNetworkDoesNotConnectToItself(t *testing.T) {
selfNodeID := ids.GenerateTestNodeID()
n := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), nil, nil, nil, selfNodeID, 1, 1)
n := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), nil, nil, nil, selfNodeID, 1, 1)
assert.NoError(t, n.Connected(context.Background(), selfNodeID, defaultPeerVersion))
assert.EqualValues(t, 0, n.Size())
}
Expand Down Expand Up @@ -93,7 +94,7 @@ func TestRequestAnyRequestsRoutingAndResponse(t *testing.T) {

codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
crossChainCodecManager := buildCodec(t, ExampleCrossChainRequest{}, ExampleCrossChainResponse{})
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 16, 16)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 16, 16)
net.SetRequestHandler(&HelloGreetingRequestHandler{codec: codecManager})
client := NewNetworkClient(net)
nodeID := ids.GenerateTestNodeID()
Expand Down Expand Up @@ -168,7 +169,7 @@ func TestRequestRequestsRoutingAndResponse(t *testing.T) {

codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
crossChainCodecManager := buildCodec(t, ExampleCrossChainRequest{}, ExampleCrossChainResponse{})
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 16, 16)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 16, 16)
net.SetRequestHandler(&HelloGreetingRequestHandler{codec: codecManager})
client := NewNetworkClient(net)

Expand Down Expand Up @@ -248,7 +249,7 @@ func TestAppRequestOnShutdown(t *testing.T) {

codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
crossChainCodecManager := buildCodec(t, ExampleCrossChainRequest{}, ExampleCrossChainResponse{})
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
client := NewNetworkClient(net)
nodeID := ids.GenerateTestNodeID()
require.NoError(t, net.Connected(context.Background(), nodeID, defaultPeerVersion))
Expand Down Expand Up @@ -297,7 +298,7 @@ func TestRequestMinVersion(t *testing.T) {
}

// passing nil as codec works because the net.AppRequest is never called
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 16)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 16)
client := NewNetworkClient(net)
requestMessage := TestMessage{Message: "this is a request"}
requestBytes, err := message.RequestToBytes(codecManager, requestMessage)
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestOnRequestHonoursDeadline(t *testing.T) {
processingDuration: 500 * time.Millisecond,
}

net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net.SetRequestHandler(requestHandler)
nodeID := ids.GenerateTestNodeID()

Expand Down Expand Up @@ -400,7 +401,7 @@ func TestGossip(t *testing.T) {
}

gossipHandler := &testGossipHandler{}
clientNetwork = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork.SetGossipHandler(gossipHandler)

assert.NoError(t, clientNetwork.Connected(context.Background(), nodeID, defaultPeerVersion))
Expand All @@ -427,7 +428,7 @@ func TestHandleInvalidMessages(t *testing.T) {
requestID := uint32(1)
sender := testAppSender{}

clientNetwork := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork.SetGossipHandler(message.NoopMempoolGossipHandler{})
clientNetwork.SetRequestHandler(&testRequestHandler{})

Expand Down Expand Up @@ -476,7 +477,7 @@ func TestNetworkPropagatesRequestHandlerError(t *testing.T) {
requestID := uint32(1)
sender := testAppSender{}

clientNetwork := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork := NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
clientNetwork.SetGossipHandler(message.NoopMempoolGossipHandler{})
clientNetwork.SetRequestHandler(&testRequestHandler{err: errors.New("fail")}) // Return an error from the request handler

Expand Down Expand Up @@ -516,7 +517,7 @@ func TestCrossChainAppRequest(t *testing.T) {
},
}

net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net.SetCrossChainRequestHandler(&testCrossChainHandler{codec: crossChainCodecManager})
client := NewNetworkClient(net)

Expand Down Expand Up @@ -571,7 +572,7 @@ func TestCrossChainRequestRequestsRoutingAndResponse(t *testing.T) {

codecManager := buildCodec(t, TestMessage{})
crossChainCodecManager := buildCodec(t, ExampleCrossChainRequest{}, ExampleCrossChainResponse{})
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net.SetCrossChainRequestHandler(&testCrossChainHandler{codec: crossChainCodecManager})
client := NewNetworkClient(net)

Expand Down Expand Up @@ -631,7 +632,7 @@ func TestCrossChainRequestOnShutdown(t *testing.T) {
}
codecManager := buildCodec(t, TestMessage{})
crossChainCodecManager := buildCodec(t, ExampleCrossChainRequest{}, ExampleCrossChainResponse{})
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
net = NewNetwork(p2p.NewRouter(logging.NoLog{}, nil, prometheus.NewRegistry(), ""), sender, codecManager, crossChainCodecManager, ids.EmptyNodeID, 1, 1)
client := NewNetworkClient(net)

exampleCrossChainRequest := ExampleCrossChainRequest{
Expand Down Expand Up @@ -664,8 +665,8 @@ func TestSDKRouting(t *testing.T) {
}
protocol := 0
handler := &testSDKHandler{}
router := p2p.NewRouter(logging.NoLog{}, sender)
_, err := router.RegisterAppProtocol(uint64(protocol), handler)
router := p2p.NewRouter(logging.NoLog{}, sender, prometheus.NewRegistry(), "")
_, err := router.RegisterAppProtocol(uint64(protocol), handler, nil)
require.NoError(err)

networkCodec := codec.NewManager(0)
Expand Down
Loading
Loading