node: refactor package node (#21105)
This PR significantly changes the APIs for instantiating Ethereum nodes in a Go program. The new APIs are not backwards-compatible, but we feel that this is made up for by the much simpler way of registering services on node.Node. You can find more information and rationale in the design document: https://gist.github.com/renaynay/5bec2de19fde66f4d04c535fd24f0775. There is also a new feature in Node's Go API: it is now possible to register arbitrary handlers on the user-facing HTTP server. In geth, this facility is used to enable GraphQL. There is a single minor change relevant for geth users in this PR: The GraphQL API is no longer available separately from the JSON-RPC HTTP server. If you want GraphQL, you need to enable it using the ./geth --http --graphql flag combination. The --graphql.port and --graphql.addr flags are no longer available.
This commit is contained in:
@ -41,8 +41,8 @@ func TestSnapshot(t *testing.T) {
|
||||
// create snapshot from ring network
|
||||
|
||||
// this is a minimal service, whose protocol will take exactly one message OR close of connection before quitting
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
|
||||
return NewNoopService(nil), nil
|
||||
},
|
||||
})
|
||||
@ -165,8 +165,8 @@ OUTER:
|
||||
// PART II
|
||||
// load snapshot and verify that exactly same connections are formed
|
||||
|
||||
adapter = adapters.NewSimAdapter(adapters.Services{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||
adapter = adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
|
||||
return NewNoopService(nil), nil
|
||||
},
|
||||
})
|
||||
@ -256,8 +256,8 @@ OuterTwo:
|
||||
t.Run("conns after load", func(t *testing.T) {
|
||||
// Create new network.
|
||||
n := NewNetwork(
|
||||
adapters.NewSimAdapter(adapters.Services{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||
adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
|
||||
return NewNoopService(nil), nil
|
||||
},
|
||||
}),
|
||||
@ -288,7 +288,7 @@ OuterTwo:
|
||||
// with each other and that a snapshot fully represents the desired topology
|
||||
func TestNetworkSimulation(t *testing.T) {
|
||||
// create simulation network with 20 testService nodes
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -437,7 +437,7 @@ func createTestNodesWithProperty(property string, count int, network *Network) (
|
||||
// It then tests again whilst excluding a node ID from being returned.
|
||||
// If a node ID is not returned, or more node IDs than expected are returned, the test fails.
|
||||
func TestGetNodeIDs(t *testing.T) {
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -486,7 +486,7 @@ func TestGetNodeIDs(t *testing.T) {
|
||||
// It then tests again whilst excluding a node from being returned.
|
||||
// If a node is not returned, or more nodes than expected are returned, the test fails.
|
||||
func TestGetNodes(t *testing.T) {
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -534,7 +534,7 @@ func TestGetNodes(t *testing.T) {
|
||||
// TestGetNodesByID creates a set of nodes and attempts to retrieve a subset of them by ID
|
||||
// If a node is not returned, or more nodes than expected are returned, the test fails.
|
||||
func TestGetNodesByID(t *testing.T) {
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -579,7 +579,7 @@ func TestGetNodesByID(t *testing.T) {
|
||||
// GetNodesByProperty is then checked for correctness by comparing the nodes returned to those initially created.
|
||||
// If a node with a property is not found, or more nodes than expected are returned, the test fails.
|
||||
func TestGetNodesByProperty(t *testing.T) {
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -624,7 +624,7 @@ func TestGetNodesByProperty(t *testing.T) {
|
||||
// GetNodeIDsByProperty is then checked for correctness by comparing the node IDs returned to those initially created.
|
||||
// If a node ID with a property is not found, or more nodes IDs than expected are returned, the test fails.
|
||||
func TestGetNodeIDsByProperty(t *testing.T) {
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"test": newTestService,
|
||||
})
|
||||
network := NewNetwork(adapter, &NetworkConfig{
|
||||
@ -705,8 +705,8 @@ func benchmarkMinimalServiceTmp(b *testing.B) {
|
||||
// this is a minimal service, whose protocol will close a channel upon run of protocol
|
||||
// making it possible to bench the time it takes for the service to start and protocol actually to be run
|
||||
protoCMap := make(map[enode.ID]map[enode.ID]chan struct{})
|
||||
adapter := adapters.NewSimAdapter(adapters.Services{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext) (node.Service, error) {
|
||||
adapter := adapters.NewSimAdapter(adapters.LifecycleConstructors{
|
||||
"noopwoop": func(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
|
||||
protoCMap[ctx.Config.ID] = make(map[enode.ID]chan struct{})
|
||||
svc := NewNoopService(protoCMap[ctx.Config.ID])
|
||||
return svc, nil
|
||||
|
Reference in New Issue
Block a user