[WIP]State diff #1
@ -17,7 +17,7 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
32
statediff/builder/builder_suite_test.go
Normal file
32
statediff/builder/builder_suite_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package builder_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStateDiffBuilder(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "StateDiff Builder Suite")
|
||||||
|
}
|
@ -17,20 +17,22 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff_test
|
package builder_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/onsi/ginkgo"
|
"github.com/onsi/ginkgo"
|
||||||
|
"github.com/onsi/gomega"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"math/big"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
statediff "github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
"github.com/onsi/gomega"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
@ -17,7 +17,7 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff
|
package builder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
@ -17,10 +17,12 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff
|
package extractor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/publisher"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Extractor interface {
|
type Extractor interface {
|
||||||
@ -28,14 +30,14 @@ type Extractor interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type extractor struct {
|
type extractor struct {
|
||||||
Builder Builder // Interface for building state diff objects from two blocks
|
Builder builder.Builder // Interface for building state diff objects from two blocks
|
||||||
Publisher Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
|
Publisher publisher.Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExtractor(builder Builder, publisher Publisher) (*extractor, error) {
|
func NewExtractor(b builder.Builder, p publisher.Publisher) (*extractor, error) {
|
||||||
return &extractor{
|
return &extractor{
|
||||||
Builder: builder,
|
Builder: b,
|
||||||
Publisher: publisher,
|
Publisher: p,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
32
statediff/extractor/extractor_suite_test.go
Normal file
32
statediff/extractor/extractor_suite_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package extractor_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStateDiffExtractor(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "StateDiff Extractor Suite")
|
||||||
|
}
|
@ -17,16 +17,19 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff_test
|
package extractor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/onsi/ginkgo"
|
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
|
||||||
"github.com/onsi/gomega"
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
|
||||||
"math/rand"
|
|
||||||
"github.com/ethereum/go-ethereum/statediff/testhelpers"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"math/rand"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
|
"github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/extractor"
|
||||||
|
statediff "github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/testhelpers"
|
||||||
)
|
)
|
||||||
var _ = ginkgo.Describe("Extractor", func() {
|
var _ = ginkgo.Describe("Extractor", func() {
|
||||||
var publisher testhelpers.MockPublisher
|
var publisher testhelpers.MockPublisher
|
||||||
@ -34,13 +37,13 @@ var _ = ginkgo.Describe("Extractor", func() {
|
|||||||
var currentBlockNumber *big.Int
|
var currentBlockNumber *big.Int
|
||||||
var parentBlock, currentBlock *types.Block
|
var parentBlock, currentBlock *types.Block
|
||||||
var expectedStateDiff statediff.StateDiff
|
var expectedStateDiff statediff.StateDiff
|
||||||
var extractor statediff.Extractor
|
var ex extractor.Extractor
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
ginkgo.BeforeEach(func() {
|
ginkgo.BeforeEach(func() {
|
||||||
publisher = testhelpers.MockPublisher{}
|
publisher = testhelpers.MockPublisher{}
|
||||||
builder = testhelpers.MockBuilder{}
|
builder = testhelpers.MockBuilder{}
|
||||||
extractor, err = statediff.NewExtractor(&builder, &publisher)
|
ex, err = extractor.NewExtractor(&builder, &publisher)
|
||||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||||
|
|
||||||
blockNumber := rand.Int63()
|
blockNumber := rand.Int63()
|
||||||
@ -61,7 +64,7 @@ var _ = ginkgo.Describe("Extractor", func() {
|
|||||||
ginkgo.It("builds a state diff struct", func() {
|
ginkgo.It("builds a state diff struct", func() {
|
||||||
builder.SetStateDiffToBuild(&expectedStateDiff)
|
builder.SetStateDiffToBuild(&expectedStateDiff)
|
||||||
|
|
||||||
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
|
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
|
||||||
|
|
||||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||||
gomega.Expect(builder.OldStateRoot).To(gomega.Equal(parentBlock.Root()))
|
gomega.Expect(builder.OldStateRoot).To(gomega.Equal(parentBlock.Root()))
|
||||||
@ -73,7 +76,7 @@ var _ = ginkgo.Describe("Extractor", func() {
|
|||||||
ginkgo.It("returns an error if building the state diff fails", func() {
|
ginkgo.It("returns an error if building the state diff fails", func() {
|
||||||
builder.SetBuilderError(testhelpers.MockError)
|
builder.SetBuilderError(testhelpers.MockError)
|
||||||
|
|
||||||
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
|
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
|
||||||
|
|
||||||
gomega.Expect(err).To(gomega.HaveOccurred())
|
gomega.Expect(err).To(gomega.HaveOccurred())
|
||||||
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))
|
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))
|
||||||
@ -82,7 +85,7 @@ var _ = ginkgo.Describe("Extractor", func() {
|
|||||||
ginkgo.It("publishes the state diff struct", func() {
|
ginkgo.It("publishes the state diff struct", func() {
|
||||||
builder.SetStateDiffToBuild(&expectedStateDiff)
|
builder.SetStateDiffToBuild(&expectedStateDiff)
|
||||||
|
|
||||||
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
|
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
|
||||||
|
|
||||||
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
gomega.Expect(err).NotTo(gomega.HaveOccurred())
|
||||||
gomega.Expect(publisher.StateDiff).To(gomega.Equal(&expectedStateDiff))
|
gomega.Expect(publisher.StateDiff).To(gomega.Equal(&expectedStateDiff))
|
||||||
@ -91,7 +94,7 @@ var _ = ginkgo.Describe("Extractor", func() {
|
|||||||
ginkgo.It("returns an error if publishing the diff fails", func() {
|
ginkgo.It("returns an error if publishing the diff fails", func() {
|
||||||
publisher.SetPublisherError(testhelpers.MockError)
|
publisher.SetPublisherError(testhelpers.MockError)
|
||||||
|
|
||||||
_, err = extractor.ExtractStateDiff(*parentBlock, *currentBlock)
|
_, err = ex.ExtractStateDiff(*parentBlock, *currentBlock)
|
||||||
|
|
||||||
gomega.Expect(err).To(gomega.HaveOccurred())
|
gomega.Expect(err).To(gomega.HaveOccurred())
|
||||||
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))
|
gomega.Expect(err).To(gomega.MatchError(testhelpers.MockError))
|
@ -24,7 +24,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||||
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
|
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Adder interface {
|
type Adder interface {
|
@ -23,9 +23,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
|
|
||||||
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
|
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -33,7 +33,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type DagPutter interface {
|
type DagPutter interface {
|
||||||
DagPut(sd *statediff.StateDiff) (string, error)
|
DagPut(sd *builder.StateDiff) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dagPutter struct {
|
type dagPutter struct {
|
||||||
@ -44,7 +44,7 @@ func NewDagPutter(adder Adder) *dagPutter {
|
|||||||
return &dagPutter{Adder: adder}
|
return &dagPutter{Adder: adder}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhdp *dagPutter) DagPut(sd *statediff.StateDiff) (string, error) {
|
func (bhdp *dagPutter) DagPut(sd *builder.StateDiff) (string, error) {
|
||||||
nd, err := bhdp.getNode(sd)
|
nd, err := bhdp.getNode(sd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -56,7 +56,7 @@ func (bhdp *dagPutter) DagPut(sd *statediff.StateDiff) (string, error) {
|
|||||||
return nd.Cid().String(), nil
|
return nd.Cid().String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhdp *dagPutter) getNode(sd *statediff.StateDiff) (ipld.Node, error) {
|
func (bhdp *dagPutter) getNode(sd *builder.StateDiff) (ipld.Node, error) {
|
||||||
|
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
enc := gob.NewEncoder(&buff)
|
enc := gob.NewEncoder(&buff)
|
@ -21,7 +21,7 @@ package ipfs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
|
mh "gx/ipfs/QmZyZDi491cCNTLfAhwcaDii2Kg4pwKRkhqQzURGDvY6ua/go-multihash"
|
||||||
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
|
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RawToCid(codec uint64, raw []byte) (*cid.Cid, error) {
|
func RawToCid(codec uint64, raw []byte) (*cid.Cid, error) {
|
||||||
@ -34,5 +34,5 @@ func RawToCid(codec uint64, raw []byte) (*cid.Cid, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return c, nil
|
return &c, nil
|
||||||
}
|
}
|
@ -20,14 +20,14 @@
|
|||||||
package ipfs
|
package ipfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ipld "gx/ipfs/QmWi2BYBL5gJ3CiAiQchg6rn1A8iBsrWy51EYxvHVjFvLb/go-ipld-format"
|
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||||
"gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
|
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
||||||
|
|
||||||
"github.com/i-norden/go-ethereum/statediff"
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StateDiffNode struct {
|
type StateDiffNode struct {
|
||||||
*statediff.StateDiff
|
*builder.StateDiff
|
||||||
|
|
||||||
cid *cid.Cid
|
cid *cid.Cid
|
||||||
rawdata []byte
|
rawdata []byte
|
||||||
@ -37,8 +37,8 @@ func (sdn *StateDiffNode) RawData() []byte {
|
|||||||
return sdn.rawdata
|
return sdn.rawdata
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sdn *StateDiffNode) Cid() *cid.Cid {
|
func (sdn *StateDiffNode) Cid() cid.Cid {
|
||||||
return sdn.cid
|
return *sdn.cid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sdn StateDiffNode) String() string {
|
func (sdn StateDiffNode) String() string {
|
@ -17,23 +17,26 @@
|
|||||||
// Contains a batch of utility type declarations used by the tests. As the node
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
// operates on unique types, a lot of them are needed to check various features.
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff
|
package publisher
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/ethereum/go-ethereum/statediff/ipfs"
|
|
||||||
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/publisher/ipfs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Publisher interface {
|
type Publisher interface {
|
||||||
PublishStateDiff(sd *StateDiff) (string, error)
|
PublishStateDiff(sd *builder.StateDiff) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type publisher struct {
|
type publisher struct {
|
||||||
ipfs.DagPutter
|
ipfs.DagPutter
|
||||||
Config
|
statediff.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPublisher(config Config) (*publisher, error) {
|
func NewPublisher(config statediff.Config) (*publisher, error) {
|
||||||
adder, err := ipfs.NewAdder(config.Path)
|
adder, err := ipfs.NewAdder(config.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -45,17 +48,17 @@ func NewPublisher(config Config) (*publisher, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *publisher) PublishStateDiff(sd *StateDiff) (string, error) {
|
func (p *publisher) PublishStateDiff(sd *builder.StateDiff) (string, error) {
|
||||||
switch p.Mode {
|
switch p.Mode {
|
||||||
case IPLD:
|
case statediff.IPLD:
|
||||||
cidStr, err := p.DagPut(sd)
|
cidStr, err := p.DagPut(sd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cidStr, err
|
return cidStr, err
|
||||||
case LDB:
|
case statediff.LDB:
|
||||||
case SQL:
|
case statediff.SQL:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
32
statediff/publisher/publisher_suite_test.go
Normal file
32
statediff/publisher/publisher_suite_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package publisher_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStateDiffPublisher(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "StateDiff Publisher Suite")
|
||||||
|
}
|
20
statediff/publisher/publisher_test.go
Normal file
20
statediff/publisher/publisher_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package publisher_test
|
@ -1,70 +0,0 @@
|
|||||||
package statediff
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
type StateDiffService struct {
|
|
||||||
builder *builder
|
|
||||||
extractor *extractor
|
|
||||||
blockchain *core.BlockChain
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewStateDiffService(db ethdb.Database, blockChain *core.BlockChain) (*StateDiffService, error) {
|
|
||||||
config := Config{}
|
|
||||||
builder := NewBuilder(db)
|
|
||||||
publisher, err := NewPublisher(config)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
extractor, _ := NewExtractor(builder, publisher)
|
|
||||||
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) loop (sub event.Subscription, events chan core.ChainHeadEvent) {
|
|
||||||
defer sub.Unsubscribe()
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case ev, ok := <-events:
|
|
||||||
if !ok {
|
|
||||||
log.Fatalf("Error getting chain head event from subscription.")
|
|
||||||
}
|
|
||||||
log.Println("doing something with an event", ev)
|
|
||||||
previousBlock := ev.Block
|
|
||||||
//TODO: figure out the best way to get the previous block
|
|
||||||
currentBlock := ev.Block
|
|
||||||
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
func (sds *StateDiffService) Start(server *p2p.Server) error {
|
|
||||||
events := make(chan core.ChainHeadEvent, 10)
|
|
||||||
sub := sds.blockchain.SubscribeChainHeadEvent(events)
|
|
||||||
|
|
||||||
go sds.loop(sub, events)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
func (StateDiffService) Stop() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
94
statediff/service/service.go
Normal file
94
statediff/service/service.go
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/extractor"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/publisher"
|
||||||
|
)
|
||||||
|
|
||||||
|
type StateDiffService struct {
|
||||||
|
builder builder.Builder
|
||||||
|
extractor extractor.Extractor
|
||||||
|
blockchain *core.BlockChain
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStateDiffService(db ethdb.Database, blockChain *core.BlockChain) (*StateDiffService, error) {
|
||||||
|
config := statediff.Config{}
|
||||||
|
b := builder.NewBuilder(db)
|
||||||
|
p, err := publisher.NewPublisher(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
e, _ := extractor.NewExtractor(b, p)
|
||||||
|
return &StateDiffService{
|
||||||
|
blockchain: blockChain,
|
||||||
|
extractor: e,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (StateDiffService) Protocols() []p2p.Protocol {
|
||||||
|
return []p2p.Protocol{}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (StateDiffService) APIs() []rpc.API {
|
||||||
|
return []rpc.API{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sds *StateDiffService) loop (sub event.Subscription, events chan core.ChainHeadEvent) {
|
||||||
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case ev, ok := <-events:
|
||||||
|
if !ok {
|
||||||
|
log.Fatalf("Error getting chain head event from subscription.")
|
||||||
|
}
|
||||||
|
log.Println("doing something with an event", ev)
|
||||||
|
previousBlock := ev.Block
|
||||||
|
//TODO: figure out the best way to get the previous block
|
||||||
|
currentBlock := ev.Block
|
||||||
|
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func (sds *StateDiffService) Start(server *p2p.Server) error {
|
||||||
|
events := make(chan core.ChainHeadEvent, 10)
|
||||||
|
sub := sds.blockchain.SubscribeChainHeadEvent(events)
|
||||||
|
|
||||||
|
go sds.loop(sub, events)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (StateDiffService) Stop() error {
|
||||||
|
return nil
|
||||||
|
}
|
32
statediff/service/service_suite_test.go
Normal file
32
statediff/service/service_suite_test.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package service_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestStateDiffService(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "StateDiff Service Suite")
|
||||||
|
}
|
20
statediff/service/service_test.go
Normal file
20
statediff/service/service_test.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
|
package service_test
|
@ -1,3 +1,22 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package statediff_test
|
package statediff_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -7,7 +26,7 @@ import (
|
|||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStatediff(t *testing.T) {
|
func TestStateDiff(t *testing.T) {
|
||||||
RegisterFailHandler(Fail)
|
RegisterFailHandler(Fail)
|
||||||
RunSpecs(t, "Statediff Suite")
|
RunSpecs(t, "StateDiff Suite")
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,28 @@
|
|||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Contains a batch of utility type declarations used by the tests. As the node
|
||||||
|
// operates on unique types, a lot of them are needed to check various features.
|
||||||
|
|
||||||
package testhelpers
|
package testhelpers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/statediff"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MockError = errors.New("mock error")
|
var MockError = errors.New("mock error")
|
||||||
@ -13,11 +32,11 @@ type MockBuilder struct {
|
|||||||
NewStateRoot common.Hash
|
NewStateRoot common.Hash
|
||||||
BlockNumber int64
|
BlockNumber int64
|
||||||
BlockHash common.Hash
|
BlockHash common.Hash
|
||||||
stateDiff *statediff.StateDiff
|
stateDiff *builder.StateDiff
|
||||||
builderError error
|
builderError error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, blockNumber int64, blockHash common.Hash) (*statediff.StateDiff, error) {
|
func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Hash, blockNumber int64, blockHash common.Hash) (*builder.StateDiff, error) {
|
||||||
builder.OldStateRoot = oldStateRoot
|
builder.OldStateRoot = oldStateRoot
|
||||||
builder.NewStateRoot = newStateRoot
|
builder.NewStateRoot = newStateRoot
|
||||||
builder.BlockNumber = blockNumber
|
builder.BlockNumber = blockNumber
|
||||||
@ -26,7 +45,7 @@ func (builder *MockBuilder) BuildStateDiff(oldStateRoot, newStateRoot common.Has
|
|||||||
return builder.stateDiff, builder.builderError
|
return builder.stateDiff, builder.builderError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (builder *MockBuilder) SetStateDiffToBuild(stateDiff *statediff.StateDiff) {
|
func (builder *MockBuilder) SetStateDiffToBuild(stateDiff *builder.StateDiff) {
|
||||||
builder.stateDiff = stateDiff
|
builder.stateDiff = stateDiff
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,11 +54,11 @@ func (builder *MockBuilder) SetBuilderError(err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MockPublisher struct{
|
type MockPublisher struct{
|
||||||
StateDiff *statediff.StateDiff
|
StateDiff *builder.StateDiff
|
||||||
publisherError error
|
publisherError error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (publisher *MockPublisher) PublishStateDiff(sd *statediff.StateDiff) (string, error) {
|
func (publisher *MockPublisher) PublishStateDiff(sd *builder.StateDiff) (string, error) {
|
||||||
publisher.StateDiff = sd
|
publisher.StateDiff = sd
|
||||||
return "", publisher.publisherError
|
return "", publisher.publisherError
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user