Skip to content

Commit

Permalink
Merge pull request 0xPolygon#5 from 0xPolygon/fix-istambul
Browse files Browse the repository at this point in the history
Fix istanbul issues
  • Loading branch information
ferranbt committed Jan 25, 2021
2 parents 994fd22 + a6fd5fe commit dabc98d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ bin/
pkg/

test-chain
.idea
28 changes: 28 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Blockchain struct {
headersCache *lru.Cache
bodiesCache *lru.Cache
difficultyCache *lru.Cache

config *chain.Params
}

var ripemd = types.StringToAddress("0000000000000000000000000000000000000003")
Expand All @@ -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{},
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion consensus/noproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 6 additions & 3 deletions minimal/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion protocol/ethereum/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit dabc98d

Please sign in to comment.