From a6fd5fe68e0d115f15c97363db5d4c75ba183df7 Mon Sep 17 00:00:00 2001 From: Ferran Date: Mon, 18 Jan 2021 13:42:39 +0100 Subject: [PATCH] Fix istambul issues --- .gitignore | 1 + blockchain/blockchain.go | 28 ++++++++++++++++++++++++++++ command/agent/agent.go | 3 +-- consensus/noproof.go | 2 +- minimal/minimal.go | 9 ++++++--- protocol/ethereum/backend.go | 2 +- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 064d93d05f..c2023bf18d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ bin/ pkg/ test-chain +.idea \ No newline at end of file diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index 3bf2de9d1c..b40dcfc0c1 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -43,6 +43,8 @@ type Blockchain struct { headersCache *lru.Cache bodiesCache *lru.Cache difficultyCache *lru.Cache + + config *chain.Params } var ripemd = types.StringToAddress("0000000000000000000000000000000000000003") @@ -53,6 +55,7 @@ var ripemdFailedTxn = types.StringToHash("0xcf416c536ec1a19ed1fb89e4ec7ffb3cf73a func NewBlockchain(db storage.Storage, config *chain.Params, consensus consensus.Consensus, executor *state.Executor) *Blockchain { b := &Blockchain{ db: db, + config: config, consensus: consensus, sidechainCh: make(chan *types.Header, 10), listeners: []chan *types.Header{}, @@ -65,6 +68,31 @@ func NewBlockchain(db storage.Storage, config *chain.Params, consensus consensus return b } +func (b *Blockchain) Config() *chain.Params { + return b.config +} + +func (b *Blockchain) CurrentHeader() (*types.Header, bool) { + return b.Header() +} + +func (b *Blockchain) GetHeader(hash types.Hash, number uint64) (*types.Header, bool) { + return b.GetHeaderByHash(hash) +} + +func (b *Blockchain) GetBlock(hash types.Hash, number uint64, full bool) (*types.Block, bool) { + return b.GetBlockByHash(hash, full) +} + +func (b *Blockchain) ReadTransactionBlockHash(hash types.Hash) (types.Hash, bool) { + // TODO + return types.Hash{}, false +} + +func (b *Blockchain) GetConsensus() consensus.Consensus { + return b.consensus +} + func (b *Blockchain) Executor() *state.Executor { return b.executor } diff --git a/command/agent/agent.go b/command/agent/agent.go index 30bbf9dfcb..7fd56da077 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -20,7 +20,6 @@ import ( consensusClique "github.com/0xPolygon/minimal/consensus/clique" consensusEthash "github.com/0xPolygon/minimal/consensus/ethash" - consensusIBFT "github.com/0xPolygon/minimal/consensus/ibft/backend" consensusPOW "github.com/0xPolygon/minimal/consensus/pow" discoveryConsul "github.com/0xPolygon/minimal/network/discovery/consul" @@ -44,7 +43,7 @@ var consensusBackends = map[string]consensus.Factory{ "clique": consensusClique.Factory, "ethash": consensusEthash.Factory, "pow": consensusPOW.Factory, - "ibft": consensusIBFT.Factory, + // "ibft": consensusIBFT.Factory, } var discoveryBackends = map[string]discovery.Factory{ diff --git a/consensus/noproof.go b/consensus/noproof.go index 05370f2975..76b60bb007 100644 --- a/consensus/noproof.go +++ b/consensus/noproof.go @@ -16,7 +16,7 @@ type NoProof struct { } // VerifyHeader verifies the header is correct -func (n *NoProof) VerifyHeader(chain ChainReader, header *types.Header, uncle, seal bool) error { +func (n *NoProof) VerifyHeader(chain ChainReader, parent, header *types.Header, uncle, seal bool) error { return nil } diff --git a/minimal/minimal.go b/minimal/minimal.go index 8417f08d75..664aa09626 100644 --- a/minimal/minimal.go +++ b/minimal/minimal.go @@ -258,9 +258,12 @@ func NewMinimal(logger hclog.Logger, config *Config) (*Minimal, error) { m.apis = append(m.apis, api) } - if istanbul, ok := m.consensus.(consensus.Istanbul); ok { - istanbul.Start(m.Blockchain, m.Blockchain.CurrentBlock, m.Blockchain.HasBadBlock) - } + /* + // TODO: FIX + if istanbul, ok := m.consensus.(consensus.Istanbul); ok { + istanbul.Start(m.Blockchain, m.Blockchain.CurrentBlock, m.Blockchain.HasBadBlock) + } + */ if err := m.server.Schedule(); err != nil { return nil, err diff --git a/protocol/ethereum/backend.go b/protocol/ethereum/backend.go index db8f7948f7..caa6ee86b5 100644 --- a/protocol/ethereum/backend.go +++ b/protocol/ethereum/backend.go @@ -337,7 +337,7 @@ func (b *Backend) announceNewBlock(e *Ethereum, p *fastrlp.Parser, v *fastrlp.Va } var block types.Block - err = block.UnmarshalRLP(p, elems[1]) + err = block.UnmarshalRLP(p.Raw(elems[1])) if err != nil { return err }