[WIP]State diff #1

Closed
elizabethengelman wants to merge 12 commits from state-diff into master
3 changed files with 73 additions and 0 deletions
Showing only changes of commit 7957c5a92b - Show all commits

View File

@ -245,6 +245,12 @@ var AppHelpFlagGroups = []flagGroup{
utils.MinerLegacyExtraDataFlag, utils.MinerLegacyExtraDataFlag,
}, },
}, },
{
Name: "STATE DIFF",
Flags: []cli.Flag{
utils.StateDiffFlag,
},
},
{ {
Name: "MISC", Name: "MISC",
}, },

View File

@ -58,6 +58,7 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
"github.com/ethereum/go-ethereum/statediff"
) )
var ( var (
@ -1338,6 +1339,18 @@ func RegisterEthStatsService(stack *node.Node, url string) {
} }
} }
func RegisterStateDiffService(stack *node.Node) {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
var ethServ *eth.Ethereum
ctx.Service(&ethServ)
chainDb := ethServ.ChainDb()
blockChain := ethServ.BlockChain()
return statediff.NewStateDiffService(chainDb, blockChain)
}); err != nil {
Fatalf("Failed to register State Diff Service", err)
}
}
func SetupMetrics(ctx *cli.Context) { func SetupMetrics(ctx *cli.Context) {
if metrics.Enabled { if metrics.Enabled {
log.Info("Enabling metrics collection") log.Info("Enabling metrics collection")

54
statediff/service.go Normal file
View File

@ -0,0 +1,54 @@
package statediff
import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb"
"fmt"
)
type StateDiffService struct {
builder *builder
extractor *extractor
blockchain *core.BlockChain
}
func NewStateDiffService(db ethdb.Database, blockChain *core.BlockChain) (*StateDiffService, error) {
config := Config{}
extractor, _ := NewExtractor(db, config)
return &StateDiffService{
blockchain: blockChain,
extractor: extractor,
}, nil
}
func (StateDiffService) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
func (StateDiffService) APIs() []rpc.API {
return []rpc.API{}
}
func (sds *StateDiffService) Start(server *p2p.Server) error {
fmt.Println("starting the state diff service")
blockChannel := make(chan core.ChainHeadEvent)
sds.blockchain.SubscribeChainHeadEvent(blockChannel)
for {
select {
case <-blockChannel:
headOfChainEvent := <-blockChannel
previousBlock := headOfChainEvent.Block
//TODO: figure out the best way to get the previous block
currentBlock := headOfChainEvent.Block
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)
}
}
return nil
}
func (StateDiffService) Stop() error {
fmt.Println("stopping the state diff service")
return nil
}