diff --git a/examples/morpheusvm/go.mod b/examples/morpheusvm/go.mod index f7896a43b8..60cca14fb0 100644 --- a/examples/morpheusvm/go.mod +++ b/examples/morpheusvm/go.mod @@ -3,7 +3,7 @@ module github.com/ava-labs/hypersdk/examples/morpheusvm go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.12-rc.2 + github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 github.com/ava-labs/hypersdk v0.0.1 github.com/fatih/color v1.13.0 github.com/onsi/ginkgo/v2 v2.13.1 @@ -16,7 +16,7 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 // indirect + github.com/ava-labs/coreth v0.13.8 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect @@ -41,7 +41,6 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/ethereum/go-ethereum v1.13.14 // indirect - github.com/fjl/memsize v0.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect diff --git a/examples/morpheusvm/go.sum b/examples/morpheusvm/go.sum index a970b362fc..5778f9bd6a 100644 --- a/examples/morpheusvm/go.sum +++ b/examples/morpheusvm/go.sum @@ -58,10 +58,10 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY 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/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.12-rc.2 h1:H1C0gsTOtwMD3qrouEqry0hfoBIC//9lEiDh/AvpaaY= -github.com/ava-labs/avalanchego v1.11.12-rc.2/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 h1:wlhGJbmb7s3bU2QWtxKjscGjfHknQiq+cVhhUjONsB8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732/go.mod h1:RkQLaQ961Xe/sUb3ycn4Qi18vPPuEetTqDf2eDcquAs= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 h1:r/vgyq3kfRwHbaBbVRZUcS5WZPHdpWODvZNLvw5udKc= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0/go.mod h1:yFlG98ykZzMHSXazQzbpfTw1D0pt/p/WEjvuZ045W1I= +github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= +github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -184,8 +184,6 @@ github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/examples/morpheusvm/scripts/run.sh b/examples/morpheusvm/scripts/run.sh index 856e9b8d77..c2e60ec553 100755 --- a/examples/morpheusvm/scripts/run.sh +++ b/examples/morpheusvm/scripts/run.sh @@ -17,7 +17,7 @@ source ../../scripts/constants.sh # shellcheck source=/scripts/common/utils.sh source ../../scripts/common/utils.sh -VERSION=v1.11.12-rc.2 +VERSION=f03745d187d0c33b927121d4c8da977789b929ac ############################ # build avalanchego diff --git a/examples/vmwithcontracts/go.mod b/examples/vmwithcontracts/go.mod index 6c7f0125fe..d2814207f9 100644 --- a/examples/vmwithcontracts/go.mod +++ b/examples/vmwithcontracts/go.mod @@ -3,7 +3,7 @@ module github.com/ava-labs/hypersdk/examples/vmwithcontracts go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.12-rc.2 + github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 github.com/ava-labs/hypersdk v0.0.16 github.com/fatih/color v1.13.0 github.com/near/borsh-go v0.3.1 @@ -18,7 +18,7 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 // indirect + github.com/ava-labs/coreth v0.13.8 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect @@ -44,7 +44,6 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/ethereum/go-ethereum v1.13.14 // indirect - github.com/fjl/memsize v0.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect diff --git a/examples/vmwithcontracts/go.sum b/examples/vmwithcontracts/go.sum index cc190f64a3..158d4d832b 100644 --- a/examples/vmwithcontracts/go.sum +++ b/examples/vmwithcontracts/go.sum @@ -58,10 +58,10 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY 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/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.12-rc.2 h1:H1C0gsTOtwMD3qrouEqry0hfoBIC//9lEiDh/AvpaaY= -github.com/ava-labs/avalanchego v1.11.12-rc.2/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 h1:wlhGJbmb7s3bU2QWtxKjscGjfHknQiq+cVhhUjONsB8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732/go.mod h1:RkQLaQ961Xe/sUb3ycn4Qi18vPPuEetTqDf2eDcquAs= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 h1:r/vgyq3kfRwHbaBbVRZUcS5WZPHdpWODvZNLvw5udKc= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0/go.mod h1:yFlG98ykZzMHSXazQzbpfTw1D0pt/p/WEjvuZ045W1I= +github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= +github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -186,8 +186,6 @@ github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/examples/vmwithcontracts/scripts/run.sh b/examples/vmwithcontracts/scripts/run.sh index 2eb833c460..a990e859ab 100755 --- a/examples/vmwithcontracts/scripts/run.sh +++ b/examples/vmwithcontracts/scripts/run.sh @@ -17,7 +17,7 @@ source ../../scripts/constants.sh # shellcheck source=/scripts/common/utils.sh source ../../scripts/common/utils.sh -VERSION=v1.11.12-rc.2 +VERSION=f03745d187d0c33b927121d4c8da977789b929ac ############################ # build avalanchego diff --git a/go.mod b/go.mod index 060f0027eb..d5973f6ca4 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ava-labs/hypersdk go 1.21.12 require ( - github.com/ava-labs/avalanchego v1.11.12-rc.2 + github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 github.com/bytecodealliance/wasmtime-go/v14 v14.0.0 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 github.com/gorilla/rpc v1.2.0 @@ -37,7 +37,7 @@ require ( github.com/DataDog/zstd v1.5.2 // indirect github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/VictoriaMetrics/fastcache v1.12.1 // indirect - github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 // indirect + github.com/ava-labs/coreth v0.13.8 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect @@ -61,7 +61,6 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 // indirect github.com/ethereum/c-kzg-4844 v0.4.0 // indirect github.com/ethereum/go-ethereum v1.13.14 // indirect - github.com/fjl/memsize v0.0.2 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect github.com/gballet/go-verkle v0.1.1-0.20231031103413-a67434b50f46 // indirect diff --git a/go.sum b/go.sum index df08f60b0f..71faf7f722 100644 --- a/go.sum +++ b/go.sum @@ -58,10 +58,10 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY 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/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/avalanchego v1.11.12-rc.2 h1:H1C0gsTOtwMD3qrouEqry0hfoBIC//9lEiDh/AvpaaY= -github.com/ava-labs/avalanchego v1.11.12-rc.2/go.mod h1:yFx3V31Jy9NFa8GZlgGnwiVf8KGjeF2+Uc99l9Scd/8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732 h1:wlhGJbmb7s3bU2QWtxKjscGjfHknQiq+cVhhUjONsB8= -github.com/ava-labs/coreth v0.13.8-fixed-genesis-upgrade.0.20240815193440-a96bc921e732/go.mod h1:RkQLaQ961Xe/sUb3ycn4Qi18vPPuEetTqDf2eDcquAs= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0 h1:r/vgyq3kfRwHbaBbVRZUcS5WZPHdpWODvZNLvw5udKc= +github.com/ava-labs/avalanchego v1.11.12-rc.2.0.20241001202925-f03745d187d0/go.mod h1:yFlG98ykZzMHSXazQzbpfTw1D0pt/p/WEjvuZ045W1I= +github.com/ava-labs/coreth v0.13.8 h1:f14X3KgwHl9LwzfxlN6S4bbn5VA2rhEsNnHaRLSTo/8= +github.com/ava-labs/coreth v0.13.8/go.mod h1:t3BSv/eQv0AlDPMfEDCMMoD/jq1RkUsbFzQAFg5qBcE= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -184,8 +184,6 @@ github.com/ethereum/go-ethereum v1.13.14 h1:EwiY3FZP94derMCIam1iW4HFVrSgIcpsu0Hw github.com/ethereum/go-ethereum v1.13.14/go.mod h1:TN8ZiHrdJwSe8Cb6x+p0hs5CxhJZPbqB7hHkaUXcmIU= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= diff --git a/internal/gossiper/gossiper.go b/internal/gossiper/gossiper.go index 6017e7890b..a2e0e192d6 100644 --- a/internal/gossiper/gossiper.go +++ b/internal/gossiper/gossiper.go @@ -7,11 +7,11 @@ import ( "context" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/engine/common" + "github.com/ava-labs/avalanchego/network/p2p" ) type Gossiper interface { - Run(common.AppSender) + Run(client *p2p.Client) Queue(context.Context) Force(context.Context) error // may be triggered by run already HandleAppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error diff --git a/internal/gossiper/manual.go b/internal/gossiper/manual.go index 4a34919d1a..134efd4924 100644 --- a/internal/gossiper/manual.go +++ b/internal/gossiper/manual.go @@ -8,6 +8,7 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/snow/engine/common" "go.uber.org/zap" @@ -19,7 +20,7 @@ var _ Gossiper = (*Manual)(nil) type Manual struct { vm VM - appSender common.AppSender + client *p2p.Client doneGossip chan struct{} } @@ -30,8 +31,8 @@ func NewManual(vm VM) *Manual { } } -func (g *Manual) Run(appSender common.AppSender) { - g.appSender = appSender +func (g *Manual) Run(client *p2p.Client) { + g.client = client // Only respond to explicitly triggered gossip close(g.doneGossip) @@ -73,7 +74,7 @@ func (g *Manual) Force(ctx context.Context) error { if err != nil { return err } - if err := g.appSender.SendAppGossip(ctx, common.SendConfig{Validators: 10}, b); err != nil { + if err := g.client.AppGossip(ctx, common.SendConfig{Validators: 10}, b); err != nil { g.vm.Logger().Warn( "GossipTxs failed", zap.Error(err), diff --git a/internal/gossiper/proposer.go b/internal/gossiper/proposer.go index 329dbcf450..80a92b6fdf 100644 --- a/internal/gossiper/proposer.go +++ b/internal/gossiper/proposer.go @@ -12,6 +12,7 @@ import ( "time" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/timer" @@ -29,7 +30,7 @@ var _ Gossiper = (*Proposer)(nil) type Proposer struct { vm VM cfg *ProposerConfig - appSender common.AppSender + client *p2p.Client doneGossip chan struct{} lastVerified int64 @@ -293,8 +294,8 @@ func (g *Proposer) Queue(context.Context) { } // periodically but less aggressively force-regossip the pending -func (g *Proposer) Run(appSender common.AppSender) { - g.appSender = appSender +func (g *Proposer) Run(client *p2p.Client) { + g.client = client defer close(g.doneGossip) // Timer blocks until stopped @@ -376,5 +377,5 @@ func (g *Proposer) sendTxs(ctx context.Context, txs []*chain.Transaction) error } recipients.Add(proposer) } - return g.appSender.SendAppGossip(ctx, common.SendConfig{NodeIDs: recipients}, b) + return g.client.AppGossip(ctx, common.SendConfig{NodeIDs: recipients}, b) } diff --git a/internal/network/network.go b/internal/network/network.go deleted file mode 100644 index b3f7531d83..0000000000 --- a/internal/network/network.go +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package network - -import ( - "context" - "sync" - "time" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/engine/common" - "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/set" - "github.com/ava-labs/avalanchego/version" - "go.uber.org/zap" -) - -type nodeIDRequester struct { - requestID uint32 - requestMapper map[uint32]*request -} - -type request struct { - handler uint8 - requestID uint32 -} - -type Manager struct { - log logging.Logger - nodeID ids.NodeID - sender common.AppSender - l sync.RWMutex - - handler uint8 - pendingHandlers map[uint8]struct{} - handlers map[uint8]Handler - - requesters map[ids.NodeID]*nodeIDRequester -} - -func NewManager(log logging.Logger, nodeID ids.NodeID, sender common.AppSender) *Manager { - return &Manager{ - log: log, - nodeID: nodeID, - sender: sender, - handlers: map[uint8]Handler{}, - pendingHandlers: map[uint8]struct{}{}, - requesters: map[ids.NodeID]*nodeIDRequester{}, - } -} - -type Handler interface { - Connected(ctx context.Context, nodeID ids.NodeID, v *version.Application) error - Disconnected(ctx context.Context, nodeID ids.NodeID) error - - AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error - - AppRequest( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - deadline time.Time, - request []byte, - ) error - AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error - AppResponse( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - response []byte, - ) error -} - -func (n *Manager) Register() (uint8, common.AppSender) { - n.l.Lock() - defer n.l.Unlock() - - newHandler := n.handler - n.pendingHandlers[newHandler] = struct{}{} - n.handler++ - return newHandler, &WrappedAppSender{n, newHandler} -} - -// Some callers take a sender before the handler is initialized, so we need to -// set the handler after initialization to avoid a potential panic. -// -// TODO: in the future allow for queueing messages during the time between -// Register and SetHandler (should both happen in init so should not be an -// issue for standard usage) -func (n *Manager) SetHandler(handler uint8, h Handler) { - n.l.Lock() - defer n.l.Unlock() - - _, ok := n.pendingHandlers[handler] - if !ok { - n.log.Error("pending handler does not exist", zap.Uint8("id", handler)) - return - } - delete(n.pendingHandlers, handler) - n.handlers[handler] = h -} - -func (n *Manager) getSharedRequestID( - handler uint8, - nodeID ids.NodeID, - requestID uint32, -) uint32 { - n.l.Lock() - defer n.l.Unlock() - - obj, ok := n.requesters[nodeID] - if !ok { - obj = &nodeIDRequester{ - requestMapper: map[uint32]*request{}, - } - n.requesters[nodeID] = obj - } - newID := obj.requestID - obj.requestMapper[newID] = &request{handler, requestID} - obj.requestID++ - return newID -} - -func (n *Manager) routeIncomingMessage(msg []byte) ([]byte, Handler, bool) { - n.l.RLock() - defer n.l.RUnlock() - - l := len(msg) - if l == 0 { - return nil, nil, false - } - handlerID := msg[0] - handler, ok := n.handlers[handlerID] - return msg[1:], handler, ok -} - -func (n *Manager) handleSharedRequestID( - nodeID ids.NodeID, - requestID uint32, -) (Handler, uint32, bool) { - n.l.Lock() - defer n.l.Unlock() - - obj, ok := n.requesters[nodeID] - if !ok { - return nil, 0, false - } - req := obj.requestMapper[requestID] - if req == nil { - return nil, 0, false - } - delete(obj.requestMapper, requestID) - return n.handlers[req.handler], req.requestID, true -} - -// Handles incoming "AppGossip" messages, parses them to transactions, -// and submits them to the mempool. The "AppGossip" message is sent by -// the other VM via "common.AppSender" to receive txs and -// forward them to the other node (validator). -// -// implements "snowmanblock.ChainVM.commom.VM.AppHandler" -// assume gossip via proposervm has been activated -// ref. "avalanchego/vms/platformvm/network.AppGossip" -func (n *Manager) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error { - parsedMsg, handler, ok := n.routeIncomingMessage(msg) - if !ok { - n.log.Debug( - "could not route incoming AppGossip", - zap.Stringer("nodeID", nodeID), - ) - return nil - } - return handler.AppGossip(ctx, nodeID, parsedMsg) -} - -// implements "block.ChainVM.commom.VM.AppHandler" -func (n *Manager) AppRequest( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - deadline time.Time, - request []byte, -) error { - parsedMsg, handler, ok := n.routeIncomingMessage(request) - if !ok { - n.log.Debug( - "could not route incoming AppRequest", - zap.Stringer("nodeID", nodeID), - zap.Uint32("requestID", requestID), - ) - return nil - } - return handler.AppRequest(ctx, nodeID, requestID, deadline, parsedMsg) -} - -// implements "block.ChainVM.commom.VM.AppHandler" -func (n *Manager) AppRequestFailed( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, -) error { - handler, cRequestID, ok := n.handleSharedRequestID(nodeID, requestID) - if !ok { - n.log.Debug( - "could not handle incoming AppRequestFailed", - zap.Stringer("nodeID", nodeID), - zap.Uint32("requestID", requestID), - ) - return nil - } - return handler.AppRequestFailed(ctx, nodeID, cRequestID) -} - -// implements "block.ChainVM.commom.VM.AppHandler" -func (n *Manager) AppResponse( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - response []byte, -) error { - handler, cRequestID, ok := n.handleSharedRequestID(nodeID, requestID) - if !ok { - n.log.Debug( - "could not handle incoming AppResponse", - zap.Stringer("nodeID", nodeID), - zap.Uint32("requestID", requestID), - ) - return nil - } - return handler.AppResponse(ctx, nodeID, cRequestID, response) -} - -// implements "block.ChainVM.commom.VM.validators.Connector" -func (n *Manager) Connected( - ctx context.Context, - nodeID ids.NodeID, - v *version.Application, -) error { - n.l.RLock() - defer n.l.RUnlock() - for k, handler := range n.handlers { - if err := handler.Connected(ctx, nodeID, v); err != nil { - n.log.Debug( - "handler could not hanlde connected message", - zap.Stringer("nodeID", nodeID), - zap.Uint8("handler", k), - zap.Error(err), - ) - } - } - return nil -} - -// implements "block.ChainVM.commom.VM.validators.Connector" -func (n *Manager) Disconnected(ctx context.Context, nodeID ids.NodeID) error { - n.l.RLock() - defer n.l.RUnlock() - for k, handler := range n.handlers { - if err := handler.Disconnected(ctx, nodeID); err != nil { - n.log.Debug( - "handler could not hanlde disconnected message", - zap.Stringer("nodeID", nodeID), - zap.Uint8("handler", k), - zap.Error(err), - ) - } - } - return nil -} - -// WrappedAppSender is used to get a shared requestID and to prepend messages -// with the handler identifier. -type WrappedAppSender struct { - n *Manager - handler uint8 -} - -// Send an application-level request. -// A nil return value guarantees that for each nodeID in [nodeIDs], -// the VM corresponding to this AppSender eventually receives either: -// * An AppResponse from nodeID with ID [requestID] -// * An AppRequestFailed from nodeID with ID [requestID] -// Exactly one of the above messages will eventually be received per nodeID. -// A non-nil error should be considered fatal. -func (w *WrappedAppSender) SendAppRequest( - ctx context.Context, - nodeIDs set.Set[ids.NodeID], - requestID uint32, - appRequestBytes []byte, -) error { - appRequestBytes = w.createMessageBytes(appRequestBytes) - for nodeID := range nodeIDs { - newRequestID := w.n.getSharedRequestID(w.handler, nodeID, requestID) - if err := w.n.sender.SendAppRequest( - ctx, - set.Of(nodeID), - newRequestID, - appRequestBytes, - ); err != nil { - return err - } - } - return nil -} - -// Send an application-level response to a request. -// This response must be in response to an AppRequest that the VM corresponding -// to this AppSender received from [nodeID] with ID [requestID]. -// A non-nil error should be considered fatal. -func (w *WrappedAppSender) SendAppResponse( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - appResponseBytes []byte, -) error { - // We don't need to wrap this response because the sender should know what - // requestID is associated with which handler. - return w.n.sender.SendAppResponse( - ctx, - nodeID, - requestID, - appResponseBytes, - ) -} - -// SendAppError sends an application-level error to an AppRequest -func (w *WrappedAppSender) SendAppError( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - errorCode int32, - errorMessage string, -) error { - return w.n.sender.SendAppError(ctx, nodeID, requestID, errorCode, errorMessage) -} - -// Gossip an application-level message. -// A non-nil error should be considered fatal. -func (w *WrappedAppSender) SendAppGossip(ctx context.Context, cfg common.SendConfig, appGossipBytes []byte) error { - return w.n.sender.SendAppGossip( - ctx, - cfg, - w.createMessageBytes(appGossipBytes), - ) -} - -func (w *WrappedAppSender) createMessageBytes(src []byte) []byte { - messageBytes := make([]byte, 1+len(src)) - messageBytes[0] = w.handler - copy(messageBytes[1:], src) - return messageBytes -} diff --git a/vm/network_state_sync.go b/vm/network_state_sync.go deleted file mode 100644 index 8554f4a459..0000000000 --- a/vm/network_state_sync.go +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package vm - -import ( - "context" - "time" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/version" -) - -type StateSyncHandler struct { - vm *VM -} - -func NewStateSyncHandler(vm *VM) *StateSyncHandler { - return &StateSyncHandler{vm} -} - -func (s *StateSyncHandler) Connected( - ctx context.Context, - nodeID ids.NodeID, - v *version.Application, -) error { - return s.vm.stateSyncNetworkClient.Connected(ctx, nodeID, v) -} - -func (s *StateSyncHandler) Disconnected(ctx context.Context, nodeID ids.NodeID) error { - return s.vm.stateSyncNetworkClient.Disconnected(ctx, nodeID) -} - -func (*StateSyncHandler) AppGossip(context.Context, ids.NodeID, []byte) error { - return nil -} - -func (s *StateSyncHandler) AppRequest( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - deadline time.Time, - request []byte, -) error { - if delay := s.vm.config.StateSyncServerDelay; delay > 0 { - time.Sleep(delay) - } - return s.vm.stateSyncNetworkServer.AppRequest(ctx, nodeID, requestID, deadline, request) -} - -func (s *StateSyncHandler) AppRequestFailed( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, -) error { - return s.vm.stateSyncNetworkClient.AppRequestFailed(ctx, nodeID, requestID) -} - -func (s *StateSyncHandler) AppResponse( - ctx context.Context, - nodeID ids.NodeID, - requestID uint32, - response []byte, -) error { - return s.vm.stateSyncNetworkClient.AppResponse(ctx, nodeID, requestID, response) -} diff --git a/vm/network_tx_gossip.go b/vm/network_tx_gossip.go index abe20b9f38..51028e2f77 100644 --- a/vm/network_tx_gossip.go +++ b/vm/network_tx_gossip.go @@ -5,61 +5,30 @@ package vm import ( "context" - "time" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/version" + "github.com/ava-labs/avalanchego/network/p2p" "go.uber.org/zap" ) +var _ p2p.Handler = (*TxGossipHandler)(nil) + type TxGossipHandler struct { + p2p.NoOpHandler vm *VM } func NewTxGossipHandler(vm *VM) *TxGossipHandler { - return &TxGossipHandler{vm} -} - -func (*TxGossipHandler) Connected(context.Context, ids.NodeID, *version.Application) error { - return nil + return &TxGossipHandler{vm: vm} } -func (*TxGossipHandler) Disconnected(context.Context, ids.NodeID) error { - return nil -} - -func (t *TxGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error { +func (t *TxGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) { if !t.vm.isReady() { t.vm.snowCtx.Log.Warn("handle app gossip failed", zap.Error(ErrNotReady)) - return nil + return } - return t.vm.gossiper.HandleAppGossip(ctx, nodeID, msg) -} - -func (*TxGossipHandler) AppRequest( - context.Context, - ids.NodeID, - uint32, - time.Time, - []byte, -) error { - return nil -} - -func (*TxGossipHandler) AppRequestFailed( - context.Context, - ids.NodeID, - uint32, -) error { - return nil -} - -func (*TxGossipHandler) AppResponse( - context.Context, - ids.NodeID, - uint32, - []byte, -) error { - return nil + if err := t.vm.gossiper.HandleAppGossip(ctx, nodeID, msg); err != nil { + t.vm.snowCtx.Log.Warn("handle app gossip failed", zap.Error(err)) + } } diff --git a/vm/syncervm_client.go b/vm/syncervm_client.go index 3bc7badf5a..a621b4198b 100644 --- a/vm/syncervm_client.go +++ b/vm/syncervm_client.go @@ -121,31 +121,19 @@ func (s *stateSyncerClient) AcceptedSyncableBlock( // Initialize metrics for sync client r := prometheus.NewRegistry() - metrics, err := avasync.NewMetrics("sync_client", r) - if err != nil { - return block.StateSyncSkipped, err - } if err := s.gatherer.Register("syncer", r); err != nil { return block.StateSyncSkipped, err } - syncClient, err := avasync.NewClient(&avasync.ClientConfig{ - BranchFactor: s.vm.genesis.GetStateBranchFactor(), - NetworkClient: s.vm.stateSyncNetworkClient, - Log: s.vm.snowCtx.Log, - Metrics: metrics, - StateSyncNodeIDs: nil, // pull from all - }) - if err != nil { - return block.StateSyncSkipped, err - } + s.syncManager, err = avasync.NewManager(avasync.ManagerConfig{ BranchFactor: s.vm.genesis.GetStateBranchFactor(), DB: s.vm.stateDB, - Client: syncClient, + RangeProofClient: s.vm.network.NewClient(rangeProofHandlerID), + ChangeProofClient: s.vm.network.NewClient(changeProofHandlerID), SimultaneousWorkLimit: s.vm.config.StateSyncParallelism, Log: s.vm.snowCtx.Log, TargetRoot: sb.StateRoot, - }) + }, r) if err != nil { return block.StateSyncSkipped, err } diff --git a/vm/vm.go b/vm/vm.go index 22b4a2a4f5..c62dd533b0 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" + "github.com/ava-labs/avalanchego/network/p2p" "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/snow/engine/common" @@ -36,7 +37,6 @@ import ( "github.com/ava-labs/hypersdk/internal/emap" "github.com/ava-labs/hypersdk/internal/gossiper" "github.com/ava-labs/hypersdk/internal/mempool" - "github.com/ava-labs/hypersdk/internal/network" "github.com/ava-labs/hypersdk/internal/pebble" "github.com/ava-labs/hypersdk/internal/trace" "github.com/ava-labs/hypersdk/internal/validators" @@ -59,6 +59,10 @@ const ( MaxAcceptorSize = 256 MinAcceptedBlockWindow = 1024 + + rangeProofHandlerID = 0x0 + changeProofHandlerID = 0x1 + txGossipHandlerID = 0x2 ) type VM struct { @@ -94,6 +98,7 @@ type VM struct { authRegistry chain.AuthRegistry outputRegistry chain.OutputRegistry authEngine map[uint8]AuthEngine + network *p2p.Network tracer avatrace.Tracer mempool *mempool.Mempool[*chain.Transaction] @@ -132,12 +137,7 @@ type VM struct { toEngine chan<- common.Message // State Sync client and AppRequest handlers - stateSyncClient *stateSyncerClient - stateSyncNetworkClient avasync.NetworkClient - stateSyncNetworkServer *avasync.NetworkServer - - // Network manager routes p2p messages to pre-registered handlers - networkManager *network.Manager + stateSyncClient *stateSyncerClient metrics *Metrics profiler profiler.ContinuousProfiler @@ -210,7 +210,11 @@ func (vm *VM) Initialize( } vm.metrics = metrics vm.proposerMonitor = validators.NewProposerMonitor(vm, vm.snowCtx) - vm.networkManager = network.NewManager(vm.snowCtx.Log, vm.snowCtx.NodeID, appSender) + + vm.network, err = p2p.NewNetwork(vm.snowCtx.Log, appSender, defaultRegistry, "p2p") + if err != nil { + return fmt.Errorf("failed to initialize p2p: %w", err) + } pebbleConfig := pebble.NewDefaultConfig() vm.vmDB, err = storage.New(pebbleConfig, vm.snowCtx.ChainDataDir, blockDB, vm.snowCtx.Metrics) @@ -424,34 +428,32 @@ func (vm *VM) Initialize( go vm.processAcceptedBlocks() // Setup state syncing - stateSyncHandler, stateSyncSender := vm.networkManager.Register() - syncRegistry := prometheus.NewRegistry() - vm.stateSyncNetworkClient, err = avasync.NewNetworkClient( - stateSyncSender, - vm.snowCtx.NodeID, - int64(vm.config.StateSyncParallelism), - vm.Logger(), - "", - syncRegistry, - nil, // TODO: populate minimum version - ) - if err != nil { + vm.stateSyncClient = vm.NewStateSyncClient(vm.snowCtx.Metrics) + + if err := vm.network.AddHandler( + rangeProofHandlerID, + avasync.NewGetRangeProofHandler(vm.snowCtx.Log, vm.stateDB), + ); err != nil { return err } - if err := vm.snowCtx.Metrics.Register("sync", syncRegistry); err != nil { + + if err := vm.network.AddHandler( + changeProofHandlerID, + avasync.NewGetChangeProofHandler(vm.snowCtx.Log, vm.stateDB), + ); err != nil { return err } - vm.stateSyncClient = vm.NewStateSyncClient(vm.snowCtx.Metrics) - vm.stateSyncNetworkServer = avasync.NewNetworkServer(stateSyncSender, vm.stateDB, vm.Logger()) - vm.networkManager.SetHandler(stateSyncHandler, NewStateSyncHandler(vm)) - // Setup gossip networking - gossipHandler, gossipSender := vm.networkManager.Register() - vm.networkManager.SetHandler(gossipHandler, NewTxGossipHandler(vm)) + if err := vm.network.AddHandler( + txGossipHandlerID, + NewTxGossipHandler(vm), + ); err != nil { + return err + } // Startup block builder and gossiper go vm.builder.Run() - go vm.gossiper.Run(gossipSender) + go vm.gossiper.Run(vm.network.NewClient(txGossipHandlerID)) // Wait until VM is ready and then send a state sync message to engine go vm.markReady() @@ -996,7 +998,7 @@ func (vm *VM) AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) erro ctx, span := vm.tracer.Start(ctx, "VM.AppGossip") defer span.End() - return vm.networkManager.AppGossip(ctx, nodeID, msg) + return vm.network.AppGossip(ctx, nodeID, msg) } // implements "block.ChainVM.commom.VM.AppHandler" @@ -1010,16 +1012,15 @@ func (vm *VM) AppRequest( ctx, span := vm.tracer.Start(ctx, "VM.AppRequest") defer span.End() - return vm.networkManager.AppRequest(ctx, nodeID, requestID, deadline, request) + return vm.network.AppRequest(ctx, nodeID, requestID, deadline, request) } // implements "block.ChainVM.commom.VM.AppHandler" -func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, _ *common.AppError) error { +func (vm *VM) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, err *common.AppError) error { ctx, span := vm.tracer.Start(ctx, "VM.AppRequestFailed") defer span.End() - // TODO: add support for handling common.AppError - return vm.networkManager.AppRequestFailed(ctx, nodeID, requestID) + return vm.network.AppRequestFailed(ctx, nodeID, requestID, err) } // implements "block.ChainVM.commom.VM.AppHandler" @@ -1032,7 +1033,7 @@ func (vm *VM) AppResponse( ctx, span := vm.tracer.Start(ctx, "VM.AppResponse") defer span.End() - return vm.networkManager.AppResponse(ctx, nodeID, requestID, response) + return vm.network.AppResponse(ctx, nodeID, requestID, response) } // implements "block.ChainVM.commom.VM.validators.Connector" @@ -1040,7 +1041,7 @@ func (vm *VM) Connected(ctx context.Context, nodeID ids.NodeID, v *version.Appli ctx, span := vm.tracer.Start(ctx, "VM.Connected") defer span.End() - return vm.networkManager.Connected(ctx, nodeID, v) + return vm.network.Connected(ctx, nodeID, v) } // implements "block.ChainVM.commom.VM.validators.Connector" @@ -1048,7 +1049,7 @@ func (vm *VM) Disconnected(ctx context.Context, nodeID ids.NodeID) error { ctx, span := vm.tracer.Start(ctx, "VM.Disconnected") defer span.End() - return vm.networkManager.Disconnected(ctx, nodeID) + return vm.network.Disconnected(ctx, nodeID) } // VerifyHeightIndex implements snowmanblock.HeightIndexedChainVM