mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
clean up Node resources when simulated backend is closed
This commit is contained in:
parent
064f37d6f6
commit
31a3ae4ccd
2 changed files with 13 additions and 7 deletions
|
|
@ -101,8 +101,8 @@ type Ethereum struct {
|
||||||
shutdownTracker *shutdowncheck.ShutdownTracker // Tracks if and when the node has shutdown ungracefully
|
shutdownTracker *shutdowncheck.ShutdownTracker // Tracks if and when the node has shutdown ungracefully
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Ethereum object (including the
|
// New creates a new Ethereum object (including the initialisation of the common Ethereum object),
|
||||||
// initialisation of the common Ethereum object)
|
// whose lifecycle will be managed by the provided node.
|
||||||
func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||||
// Ensure configuration values are compatible and sane
|
// Ensure configuration values are compatible and sane
|
||||||
if config.SyncMode == downloader.LightSync {
|
if config.SyncMode == downloader.LightSync {
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ type simClient struct {
|
||||||
// Backend is a simulated blockchain. You can use it to test your contracts or
|
// Backend is a simulated blockchain. You can use it to test your contracts or
|
||||||
// other code that interacts with the Ethereum chain.
|
// other code that interacts with the Ethereum chain.
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
eth *eth.Ethereum
|
node *node.Node
|
||||||
beacon *catalyst.SimulatedBeacon
|
beacon *catalyst.SimulatedBeacon
|
||||||
client simClient
|
client simClient
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +129,7 @@ func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backe
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Backend{
|
return &Backend{
|
||||||
eth: backend,
|
node: stack,
|
||||||
beacon: beacon,
|
beacon: beacon,
|
||||||
client: simClient{ethclient.NewClient(stack.Attach())},
|
client: simClient{ethclient.NewClient(stack.Attach())},
|
||||||
}, nil
|
}, nil
|
||||||
|
|
@ -142,12 +142,18 @@ func (n *Backend) Close() error {
|
||||||
n.client.Close()
|
n.client.Close()
|
||||||
n.client = simClient{}
|
n.client = simClient{}
|
||||||
}
|
}
|
||||||
|
var rerr error // return only last error if there are multiple
|
||||||
if n.beacon != nil {
|
if n.beacon != nil {
|
||||||
err := n.beacon.Stop()
|
rerr = n.beacon.Stop()
|
||||||
n.beacon = nil
|
n.beacon = nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
return nil
|
if n.node != nil {
|
||||||
|
if err := n.node.Close(); err != nil {
|
||||||
|
rerr = err
|
||||||
|
}
|
||||||
|
n.node = nil
|
||||||
|
}
|
||||||
|
return rerr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit seals a block and moves the chain forward to a new empty block.
|
// Commit seals a block and moves the chain forward to a new empty block.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue