Skip to content

Commit

Permalink
Manual revert ethereum#520 "Persist Proposer state across restarts" (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Cortesi authored and celo-ci-bot-user committed Nov 19, 2019
1 parent 6d301e4 commit ecf58f1
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 262 deletions.
3 changes: 0 additions & 3 deletions consensus/istanbul/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,4 @@ type Backend interface {

// Authorize injects a private key into the consensus engine.
Authorize(address common.Address, signFn SignerFn, signHashBLSFn SignerFn, signMessageBLSFn MessageSignerFn)

// GetDataDir returns a read-write enabled data dir in which data will persist across restarts.
GetDataDir() string
}
8 changes: 1 addition & 7 deletions consensus/istanbul/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type AnnounceGossipTimestamp struct {
}

// New creates an Ethereum backend for Istanbul core engine.
func New(config *istanbul.Config, db ethdb.Database, dataDir string) consensus.Istanbul {
func New(config *istanbul.Config, db ethdb.Database) consensus.Istanbul {
// Allocate the snapshot caches and create the engine
logger := log.New()
recentSnapshots, err := lru.NewARC(inmemorySnapshots)
Expand Down Expand Up @@ -93,7 +93,6 @@ func New(config *istanbul.Config, db ethdb.Database, dataDir string) consensus.I
announceWg: new(sync.WaitGroup),
announceQuit: make(chan struct{}),
lastAnnounceGossiped: make(map[common.Address]*AnnounceGossipTimestamp),
dataDir: dataDir,
}
backend.core = istanbulCore.New(backend, backend.config)
table, err := enodes.OpenValidatorEnodeDB(config.ValidatorEnodeDBPath, &validatorPeerHandler{sb: backend})
Expand Down Expand Up @@ -151,7 +150,6 @@ type Backend struct {

announceWg *sync.WaitGroup
announceQuit chan struct{}
dataDir string // A read-write data dir to persist files across restarts
newEpochCh chan struct{}
}

Expand Down Expand Up @@ -262,10 +260,6 @@ func (sb *Backend) GetNodeKey() *ecdsa.PrivateKey {
return nil
}

func (sb *Backend) GetDataDir() string {
return sb.dataDir
}

// Commit implements istanbul.Backend.Commit
func (sb *Backend) Commit(proposal istanbul.Proposal, aggregatedSeal types.IstanbulAggregatedSeal) error {
// Check if the proposal is a valid block
Expand Down
6 changes: 2 additions & 4 deletions consensus/istanbul/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@ package backend
import (
//"bytes"
"crypto/ecdsa"
"fmt"
"math/big"
"strings"
"testing"
"time"

"github.com/celo-org/bls-zexe/go"
bls "github.com/celo-org/bls-zexe/go"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/istanbul"
"github.com/ethereum/go-ethereum/consensus/istanbul/validator"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/bls"
blscrypto "github.com/ethereum/go-ethereum/crypto/bls"
)

func TestSign(t *testing.T) {
Expand Down Expand Up @@ -179,7 +178,6 @@ func TestCommit(t *testing.T) {

func TestGetProposer(t *testing.T) {
chain, engine := newBlockChain(1, true)
fmt.Printf("Data dir is %s\n", engine.GetDataDir())
block := makeBlock(chain, engine, chain.Genesis())
chain.InsertChain(types.Blocks{block})
expected := engine.GetProposer(1)
Expand Down
23 changes: 1 addition & 22 deletions consensus/istanbul/backend/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import (
"bytes"
"crypto/ecdsa"
"math/big"
"math/rand"
"os"
"path/filepath"
"reflect"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -112,8 +108,7 @@ func newBlockChain(n int, isFullChain bool) (*core.BlockChain, *Backend) {
return signatureBytes, nil
}

dataDir := createRandomDataDir()
b, _ := New(config, memDB, dataDir).(*Backend)
b, _ := New(config, memDB).(*Backend)
b.Authorize(address, signerFn, signerBLSHashFn, signerBLSMessageFn)

genesis.MustCommit(memDB)
Expand Down Expand Up @@ -213,22 +208,6 @@ func newBlockChain(n int, isFullChain bool) (*core.BlockChain, *Backend) {
return blockchain, b
}

func createRandomDataDir() string {
rand.Seed(time.Now().UnixNano())
for {
dirName := "geth_ibft_" + strconv.Itoa(rand.Int()%1000000)
dataDir := filepath.Join("/tmp", dirName)
err := os.Mkdir(dataDir, 0700)
if os.IsExist(err) {
continue // Re-try
}
if err != nil {
panic("Failed to create dir: " + dataDir + " error: " + err.Error())
}
return dataDir
}
}

func getGenesisAndKeys(n int, isFullChain bool) (*core.Genesis, []*ecdsa.PrivateKey) {
// Setup validators
var nodeKeys = make([]*ecdsa.PrivateKey, n)
Expand Down
5 changes: 1 addition & 4 deletions consensus/istanbul/backend/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"bytes"
"crypto/ecdsa"
"math/big"
"math/rand"
"path/filepath"
"reflect"
"testing"

Expand Down Expand Up @@ -264,8 +262,7 @@ func TestValSetChange(t *testing.T) {
headers: make(map[uint64]*types.Header),
}

dataDir := filepath.Join("/tmp", string(rand.Int()))
engine := New(config, db, dataDir).(*Backend)
engine := New(config, db).(*Backend)

privateKey := accounts.accounts[tt.validators[0]]
address := crypto.PubkeyToAddress(privateKey.PublicKey)
Expand Down
1 change: 0 additions & 1 deletion consensus/istanbul/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ func (c *core) startNewRound(round *big.Int) {
} else {
if c.current != nil {
request = c.current.PendingRequest()
c.deleteMessageFromDisk(c.current.Round(), c.current.Sequence())
}
newView = &istanbul.View{
Sequence: new(big.Int).Add(lastProposal.Number(), common.Big1),
Expand Down
109 changes: 0 additions & 109 deletions consensus/istanbul/core/persistent_state.go

This file was deleted.

45 changes: 6 additions & 39 deletions consensus/istanbul/core/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"github.com/ethereum/go-ethereum/log"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -30,7 +29,12 @@ func (c *core) sendPreprepare(request *istanbul.Request, roundChangeCertificate

// If I'm the proposer and I have the same sequence with the proposal
if c.current.Sequence().Cmp(request.Proposal.Number()) == 0 && c.isProposer() {
preprepare, err := c.getPreprepareMessage(request, roundChangeCertificate, logger)
curView := c.currentView()
preprepare, err := Encode(&istanbul.Preprepare{
View: curView,
Proposal: request.Proposal,
RoundChangeCertificate: roundChangeCertificate,
})
if err != nil {
logger.Error("Failed to prepare message")
return
Expand All @@ -45,43 +49,6 @@ func (c *core) sendPreprepare(request *istanbul.Request, roundChangeCertificate
}
}

func (c *core) getPreprepareMessage(
request *istanbul.Request,
roundChangeCertificate istanbul.RoundChangeCertificate,
logger log.Logger) ([]byte, error) {
curView := c.currentView()
messageType := istanbul.MsgPreprepare
roundNumber := c.current.Round()
sequenceNumber := c.current.Sequence()
existingPreparedMessage, err := c.getPreprepareMessageFromDisk(
messageType, roundNumber, sequenceNumber)
if err != nil {
logger.Error("Failed to get prepared message from disk", "view", curView)
return nil, err
}

if existingPreparedMessage != nil {
logger.Info("Got previously prepared messaged from the disk", "msg", existingPreparedMessage)
return existingPreparedMessage, nil
}

preprepare, err := Encode(&istanbul.Preprepare{
View: curView,
Proposal: request.Proposal,
RoundChangeCertificate: roundChangeCertificate,
})
if err != nil {
logger.Error("Failed to encode", "view", curView)
return nil, err
}
err2 := c.savePrepareMessageToDisk(messageType, roundNumber, sequenceNumber, preprepare)
if err2 != nil {
logger.Error("Failed to write prepare message to the disk", "msg", preprepare)
return nil, err2
}
return preprepare, nil
}

func (c *core) handlePreprepare(msg *istanbul.Message) error {
logger := c.logger.New("from", msg.Address, "state", c.state, "cur_round", c.current.Round(), "cur_seq", c.current.Sequence(), "func", "handlePreprepare", "tag", "handleMsg")
logger.Trace("Got pre-prepare message", "msg", msg)
Expand Down
Loading

0 comments on commit ecf58f1

Please sign in to comment.