Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions cmd/platon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ func platon(ctx *cli.Context) error {
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isConsole bool) {
debug.Memsize.Add("node", stack)

// Start up the node itself
utils.StartNode(ctx, stack, isConsole)

Expand Down
3 changes: 2 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (

"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/types"
"github.com/PlatONnetwork/PlatON-Go/core"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"
types2 "github.com/PlatONnetwork/PlatON-Go/core/types"
"github.com/PlatONnetwork/PlatON-Go/core/vm"

Expand Down Expand Up @@ -1498,7 +1499,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
Fatalf("%v", err)
}

var engine consensus.Engine
var engine sdk.Engine
//todo: Merge confirmation.
engine = consensus.NewFaker()

Expand Down
24 changes: 16 additions & 8 deletions common/mock/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (c *Chain) AddBlockWithTxHashAndCommit(txHash common.Hash, miner bool, f fu
}

func (c *Chain) execTx(miner bool, f Transaction) error {
c.StateDB.TxIndex++
c.StateDB.Prepare(f.Hash(), c.StateDB.TxIndex)
c.StateDB.txIndex++
c.StateDB.Prepare(f.Hash(), c.StateDB.TxIndex())
if miner {
return f(common.ZeroHash, c.CurrentHeader(), c.StateDB)
} else {
Expand Down Expand Up @@ -370,7 +370,7 @@ type MockStateDB struct {
Balance map[common.Address]*big.Int
State map[common.Address]map[string][]byte
Thash common.Hash
TxIndex int
txIndex int
logSize uint
Logs map[common.Hash][]*types.Log
Journal *journal
Expand All @@ -381,13 +381,21 @@ type MockStateDB struct {

func (s *MockStateDB) Prepare(thash common.Hash, ti int) {
s.Thash = thash
s.TxIndex = ti
s.txIndex = ti
}

func (s *MockStateDB) TxIndex() int {
return s.txIndex
}

func (s *MockStateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
return common.ZeroHash
}

func (s *MockStateDB) Finalise(bool) {

}

func (s *MockStateDB) SubBalance(adr common.Address, amount *big.Int) {
if balance, ok := s.Balance[adr]; ok {
s.Journal.append(balanceChange{
Expand Down Expand Up @@ -578,7 +586,7 @@ func (s *MockStateDB) AddLog(logInfo *types.Log) {
s.Journal.append(addLogChange{txhash: s.Thash})

logInfo.TxHash = s.Thash
logInfo.TxIndex = uint(s.TxIndex)
logInfo.TxIndex = uint(s.TxIndex())
logInfo.Index = s.logSize
s.Logs[s.Thash] = append(s.Logs[s.Thash], logInfo)
s.logSize++
Expand Down Expand Up @@ -610,7 +618,7 @@ func (s *MockStateDB) TxHash() common.Hash {
return s.Thash
}
func (s *MockStateDB) TxIdx() uint32 {
return uint32(s.TxIndex)
return uint32(s.TxIndex())
}

func (s *MockStateDB) PrepareAccessList(common.Address, *common.Address, []common.Address, types.AccessList) {
Expand Down Expand Up @@ -678,7 +686,7 @@ func (s *MockStateDB) Equal(other *MockStateDB) bool {
return false
}

if s.TxIndex != other.TxIndex {
if s.txIndex != other.txIndex {
return false
}

Expand Down Expand Up @@ -747,7 +755,7 @@ func (lhs *MockStateDB) DeepCopy(rhs *MockStateDB) {
}

lhs.Thash = rhs.Thash
lhs.TxIndex = rhs.TxIndex
lhs.txIndex = rhs.txIndex
lhs.logSize = rhs.logSize

if nil != rhs.Logs {
Expand Down
18 changes: 9 additions & 9 deletions consensus/bft_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (bm *BftMock) FastSyncCommitHead(block *types.Block) error {
}

// Start is a fake interface, no need to implement.
func (bm *BftMock) Start(chain ChainReader, blockCacheWriter BlockCacheWriter, pool TxPoolReset, sdkBackend sdk.Backend) error {
func (bm *BftMock) Start(chain sdk.ChainReader, blockCacheWriter sdk.BlockCacheWriter, pool sdk.TxPoolReset, sdkBackend sdk.Backend) error {
return nil
}

Expand Down Expand Up @@ -172,7 +172,7 @@ func (bm *BftMock) Author(header *types.Header) (common.Address, error) {
// VerifyHeader checks whether a header conforms to the consensus rules of a
// given engine. Verifying the seal may be done optionally here, or explicitly
// via the VerifySeal method.
func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, seal bool) error {
func (bm *BftMock) VerifyHeader(chain sdk.ChainReader, header *types.Header, seal bool) error {
if bm.fakeFail == header.Number.Uint64() {
return fmt.Errorf("failed verifyHeader on bftMock")
}
Expand All @@ -183,7 +183,7 @@ func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, seal bo
// concurrently. The method returns a quit channel to abort the operations and
// a results channel to retrieve the async verifications (the order is that of
// the input slice).
func (bm *BftMock) VerifyHeaders(chain ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
func (bm *BftMock) VerifyHeaders(chain sdk.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
results := make(chan error, len(headers))
c := make(chan<- struct{})

Expand All @@ -203,13 +203,13 @@ func (bm *BftMock) VerifyHeaders(chain ChainReader, headers []*types.Header, sea

// VerifySeal checks whether the crypto seal on a header is valid according to
// the consensus rules of the given engine.
func (bm *BftMock) VerifySeal(chain ChainReader, header *types.Header) error {
func (bm *BftMock) VerifySeal(chain sdk.ChainReader, header *types.Header) error {
return nil
}

// Prepare initializes the consensus fields of a block header according to the
// rules of a particular engine. The changes are executed inline.
func (bm *BftMock) Prepare(chain ChainReader, header *types.Header) error {
func (bm *BftMock) Prepare(chain sdk.ChainReader, header *types.Header) error {
//header.Extra[0:31] to store block's version info etc. and right pad with 0x00;
//header.Extra[32:] to store block's sign of producer, the length of sign is 65.
if len(header.Extra) < 32 {
Expand All @@ -225,7 +225,7 @@ func (bm *BftMock) Prepare(chain ChainReader, header *types.Header) error {
// and assembles the final block.
// Note: The block header and state database might be updated to reflect any
// consensus rules that happen at finalization (e.g. block rewards).
func (bm *BftMock) Finalize(chain ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
func (bm *BftMock) Finalize(chain sdk.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction,
receipts []*types.Receipt) (*types.Block, error) {
header.Root = state.IntermediateRoot(true)

Expand All @@ -238,7 +238,7 @@ func (bm *BftMock) Finalize(chain ChainReader, header *types.Header, state *stat
//
// Note, the method returns immediately and will send the result async. More
// than one result may also be returned depending on the consensus algorithm.
func (bm *BftMock) Seal(chain ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{}) error {
func (bm *BftMock) Seal(chain sdk.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{}) error {

header := block.Header()
if block.NumberU64() == 0 {
Expand Down Expand Up @@ -266,12 +266,12 @@ func (bm *BftMock) SealHash(header *types.Header) common.Hash {

// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
// that a new block should have.
func (bm *BftMock) CalcDifficulty(chain ChainReader, time uint64, parent *types.Header) *big.Int {
func (bm *BftMock) CalcDifficulty(chain sdk.ChainReader, time uint64, parent *types.Header) *big.Int {
return nil
}

// APIs returns the RPC APIs this consensus engine provides.
func (bm *BftMock) APIs(chain ChainReader) []rpc.API {
func (bm *BftMock) APIs(chain sdk.ChainReader) []rpc.API {
return nil
}

Expand Down
36 changes: 17 additions & 19 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ import (
"sync/atomic"
"time"

"github.com/PlatONnetwork/PlatON-Go/common/base"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"

mapset "github.com/deckarep/golang-set"
"github.com/pkg/errors"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/base"
"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
"github.com/PlatONnetwork/PlatON-Go/consensus"
"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/context"
Expand All @@ -52,6 +47,7 @@ import (
"github.com/PlatONnetwork/PlatON-Go/consensus/cbft/wal"
"github.com/PlatONnetwork/PlatON-Go/consensus/misc"
"github.com/PlatONnetwork/PlatON-Go/core/cbfttypes"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"
"github.com/PlatONnetwork/PlatON-Go/core/state"
"github.com/PlatONnetwork/PlatON-Go/core/types"
"github.com/PlatONnetwork/PlatON-Go/crypto"
Expand All @@ -64,6 +60,8 @@ import (
"github.com/PlatONnetwork/PlatON-Go/params"
"github.com/PlatONnetwork/PlatON-Go/rpc"
"github.com/PlatONnetwork/PlatON-Go/trie"
mapset "github.com/deckarep/golang-set"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -118,9 +116,9 @@ type Cbft struct {
eventMux *event.TypeMux
closeOnce sync.Once
exitCh chan struct{}
txPool consensus.TxPoolReset
blockChain consensus.ChainReader
blockCacheWriter consensus.BlockCacheWriter
txPool sdk.TxPoolReset
blockChain sdk.ChainReader
blockCacheWriter sdk.BlockCacheWriter
peerMsgCh chan *ctypes.MsgInfo
syncMsgCh chan *ctypes.MsgInfo
evPool evidence.EvidencePool
Expand Down Expand Up @@ -226,7 +224,7 @@ func New(sysConfig *params.CbftConfig, optConfig *ctypes.OptionsConfig, eventMux
}

// Start starts consensus engine.
func (cbft *Cbft) Start(chain consensus.ChainReader, blockCacheWriter consensus.BlockCacheWriter, txPool consensus.TxPoolReset, sdkBackend sdk.Backend) error {
func (cbft *Cbft) Start(chain sdk.ChainReader, blockCacheWriter sdk.BlockCacheWriter, txPool sdk.TxPoolReset, sdkBackend sdk.Backend) error {
cbft.log.Info("~ Start cbft consensus")
cbft.blockChain = chain
cbft.txPool = txPool
Expand Down Expand Up @@ -646,7 +644,7 @@ func (cbft *Cbft) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}

func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error {
func (cbft *Cbft) VerifyHeader(chain sdk.ChainReader, header *types.Header, seal bool) error {
// Short circuit if the header is known, or its parent not
number := header.Number.Uint64()
if chain.GetHeader(header.Hash(), number) != nil {
Expand All @@ -669,7 +667,7 @@ func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header
}

// VerifyHeader verify the validity of the block header.
func (cbft *Cbft) verifyHeader(chain consensus.ChainReader, header *types.Header, parent *types.Header, seal bool) error {
func (cbft *Cbft) verifyHeader(chain sdk.ChainReader, header *types.Header, parent *types.Header, seal bool) error {
if header.Number == nil {
cbft.log.Error("Verify header fail, unknown block")
return ErrorUnKnowBlock
Expand Down Expand Up @@ -720,7 +718,7 @@ func (cbft *Cbft) verifyHeader(chain consensus.ChainReader, header *types.Header
}

// VerifyHeaders is used to verify the validity of block headers in batch.
func (cbft *Cbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
func (cbft *Cbft) VerifyHeaders(chain sdk.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
abort := make(chan struct{})
results := make(chan error, len(headers))

Expand All @@ -738,7 +736,7 @@ func (cbft *Cbft) VerifyHeaders(chain consensus.ChainReader, headers []*types.He
return abort, results
}

func (cbft *Cbft) verifyHeaderWorker(chain consensus.ChainReader, headers []*types.Header, index int) error {
func (cbft *Cbft) verifyHeaderWorker(chain sdk.ChainReader, headers []*types.Header, index int) error {
var parent *types.Header
if index == 0 {
parent = chain.GetHeader(headers[0].ParentHash, headers[0].Number.Uint64()-1)
Expand All @@ -761,7 +759,7 @@ func (cbft *Cbft) verifyHeaderWorker(chain consensus.ChainReader, headers []*typ

// VerifySeal implements consensus.Engine, checking whether the signature contained
// in the header satisfies the consensus protocol requirements.
func (cbft *Cbft) VerifySeal(chain consensus.ChainReader, header *types.Header) error {
func (cbft *Cbft) VerifySeal(chain sdk.ChainReader, header *types.Header) error {
if header.Number.Uint64() == 0 {
return ErrorUnKnowBlock
}
Expand All @@ -770,7 +768,7 @@ func (cbft *Cbft) VerifySeal(chain consensus.ChainReader, header *types.Header)

// Prepare implements consensus.Engine, preparing all the consensus fields of the
// header of running the transactions on top.
func (cbft *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) error {
func (cbft *Cbft) Prepare(chain sdk.ChainReader, header *types.Header) error {
cbft.log.Debug("Prepare", "hash", header.Hash(), "number", header.Number.Uint64())

//header.Extra[0:31] to store block's version info etc. and right pad with 0x00;
Expand All @@ -796,15 +794,15 @@ func (cbft *Cbft) Prepare(chain consensus.ChainReader, header *types.Header) err

// Finalize implements consensus.Engine, no block
// rewards given, and returns the final block.
func (cbft *Cbft) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error) {
func (cbft *Cbft) Finalize(chain sdk.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt) (*types.Block, error) {
header.Root = state.IntermediateRoot(true)
cbft.log.Debug("Finalize block", "hash", header.Hash(), "number", header.Number, "txs", len(txs), "receipts", len(receipts), "root", header.Root.String())
return types.NewBlock(header, txs, receipts, new(trie.Trie)), nil
}

// Seal is used to generate a block, and block data is
// passed to the execution channel.
func (cbft *Cbft) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{}) error {
func (cbft *Cbft) Seal(chain sdk.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}, complete chan<- struct{}) error {
cbft.log.Info("Seal block", "number", block.Number(), "parentHash", block.ParentHash())
header := block.Header()
if block.NumberU64() == 0 {
Expand Down Expand Up @@ -935,7 +933,7 @@ func (cbft *Cbft) SealHash(header *types.Header) common.Hash {
}

// APIs returns a list of APIs provided by the consensus engine.
func (cbft *Cbft) APIs(chain consensus.ChainReader) []rpc.API {
func (cbft *Cbft) APIs(chain sdk.ChainReader) []rpc.API {
return []rpc.API{
{
Namespace: "debug",
Expand Down
2 changes: 2 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// Package consensus implements different Ethereum consensus engines.
package consensus

/*
import (
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"
Expand Down Expand Up @@ -188,3 +189,4 @@ type Bft interface {
// NodeID is temporary.
Node() *enode.Node
}
*/
7 changes: 4 additions & 3 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ package core

import (
"fmt"

"github.com/PlatONnetwork/PlatON-Go/trie"

"github.com/PlatONnetwork/PlatON-Go/log"

"github.com/PlatONnetwork/PlatON-Go/consensus"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"
"github.com/PlatONnetwork/PlatON-Go/core/state"
"github.com/PlatONnetwork/PlatON-Go/core/types"
"github.com/PlatONnetwork/PlatON-Go/params"
Expand All @@ -35,11 +36,11 @@ import (
type BlockValidator struct {
config *params.ChainConfig // Chain configuration options
bc *BlockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
engine sdk.Engine // Consensus engine used for validating
}

// NewBlockValidator returns a new block validator which is safe for re-use
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine consensus.Engine) *BlockValidator {
func NewBlockValidator(config *params.ChainConfig, blockchain *BlockChain, engine sdk.Engine) *BlockValidator {
validator := &BlockValidator{
config: config,
engine: engine,
Expand Down
8 changes: 4 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ package core
import (
"errors"
"fmt"
"github.com/PlatONnetwork/PlatON-Go/consensus"
"github.com/PlatONnetwork/PlatON-Go/core/sdk"
"io"
mrand "math/rand"
"sort"
"sync"
"sync/atomic"
"time"

"github.com/PlatONnetwork/PlatON-Go/core/sdk"

"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/common/mclock"
"github.com/PlatONnetwork/PlatON-Go/common/prque"
Expand Down Expand Up @@ -241,7 +241,7 @@ type BlockChain struct {
procInterrupt int32 // interrupt signaler for block processing
executeWG sync.WaitGroup // execute block processing wait group for shutting dow

engine consensus.Engine
engine sdk.Engine
processor Processor // block processor interface
validator Validator // block and state validator interface
vmConfig vm.Config
Expand All @@ -254,7 +254,7 @@ type BlockChain struct {
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and
// Processor.
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, txLookupLimit *uint64, app types.App) (*BlockChain, error) {
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine sdk.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool, txLookupLimit *uint64, app types.App) (*BlockChain, error) {
if cacheConfig == nil {
cacheConfig = defaultCacheConfig
}
Expand Down
Loading
Loading