Skip to content

Commit fdaff84

Browse files
authored
Merge pull request ethereum#23 from rus-alex/blockchain-interface-segregation
snap.BlockChain interface instead of *core.BlockChain
2 parents 721b87d + 63ba82e commit fdaff84

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

eth/handler_snap.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package eth
1818

1919
import (
20-
"github.com/ethereum/go-ethereum/core"
2120
"github.com/ethereum/go-ethereum/eth/protocols/snap"
2221
"github.com/ethereum/go-ethereum/p2p/enode"
2322
)
@@ -26,7 +25,7 @@ import (
2625
// packets that are sent as replies or broadcasts.
2726
type snapHandler handler
2827

29-
func (h *snapHandler) Chain() *core.BlockChain { return h.chain }
28+
func (h *snapHandler) Chain() snap.BlockChain { return h.chain }
3029

3130
// RunPeer is invoked when a peer joins on the `snap` protocol.
3231
func (h *snapHandler) RunPeer(peer *snap.Peer, hand snap.Handler) error {

eth/protocols/snap/handler.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"time"
2323

2424
"github.com/ethereum/go-ethereum/common"
25-
"github.com/ethereum/go-ethereum/core"
2625
"github.com/ethereum/go-ethereum/core/state"
26+
"github.com/ethereum/go-ethereum/core/state/snapshot"
2727
"github.com/ethereum/go-ethereum/light"
2828
"github.com/ethereum/go-ethereum/log"
2929
"github.com/ethereum/go-ethereum/metrics"
@@ -61,11 +61,21 @@ const (
6161
// exchanges have passed.
6262
type Handler func(peer *Peer) error
6363

64+
type BlockChain interface {
65+
// StateCache returns the caching database underpinning the blockchain instance.
66+
StateCache() state.Database
67+
// ContractCode retrieves a blob of data associated with a contract hash
68+
// either from ephemeral in-memory cache, or from persistent storage.
69+
ContractCode(hash common.Hash) ([]byte, error)
70+
// Snapshots returns the blockchain snapshot tree.
71+
Snapshots() *snapshot.Tree
72+
}
73+
6474
// Backend defines the data retrieval methods to serve remote requests and the
6575
// callback methods to invoke on remote deliveries.
6676
type Backend interface {
6777
// Chain retrieves the blockchain object to serve data.
68-
Chain() *core.BlockChain
78+
Chain() BlockChain
6979

7080
// RunPeer is invoked when a peer joins on the `eth` protocol. The handler
7181
// should do any peer maintenance work, handshakes and validations. If all
@@ -523,6 +533,6 @@ func handleMessage(backend Backend, peer *Peer) error {
523533
type NodeInfo struct{}
524534

525535
// nodeInfo retrieves some `snap` protocol metadata about the running host node.
526-
func nodeInfo(chain *core.BlockChain) *NodeInfo {
536+
func nodeInfo(BlockChain) *NodeInfo {
527537
return &NodeInfo{}
528538
}

0 commit comments

Comments
 (0)