Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raft difficulty to fixed value of 1 #45

Open
wants to merge 9 commits into
base: kaleido-dev
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var (
utils.CacheSnapshotFlag,
utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.FDLimitFlag,
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.CacheSnapshotFlag,
utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.FDLimitFlag,
},
},
{
Expand Down
23 changes: 20 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ var (
Name: "cache.preimages",
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
}
FDLimitFlag = cli.IntFlag{
Name: "fdlimit",
Usage: "Raise the open file descriptor resource limit (default = system fd limit)",
}
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
Expand Down Expand Up @@ -1359,11 +1363,24 @@ func setLes(ctx *cli.Context, cfg *ethconfig.Config) {

// MakeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
func MakeDatabaseHandles(max int) int {
limit, err := fdlimit.Maximum()
if err != nil {
Fatalf("Failed to retrieve file descriptor allowance: %v", err)
}
switch {
case max == 0:
// User didn't specify a meaningful value, use system limits
case max < 128:
// User specified something unhealthy, just use system defaults
log.Error("File descriptor limit invalid (<128)", "had", max, "updated", limit)
case max > limit:
// User requested more than the OS allows, notify that we can't allocate it
log.Warn("Requested file descriptors denied by OS", "req", max, "limit", limit)
default:
// User limit is meaningful and within allowed range, use that
limit = max
}
raised, err := fdlimit.Raise(uint64(limit))
if err != nil {
Fatalf("Failed to raise file descriptor allowance: %v", err)
Expand Down Expand Up @@ -2064,7 +2081,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
}
cfg.DatabaseHandles = MakeDatabaseHandles()
cfg.DatabaseHandles = MakeDatabaseHandles(ctx.GlobalInt(FDLimitFlag.Name))
if ctx.GlobalIsSet(AncientFlag.Name) {
cfg.DatabaseFreezer = ctx.GlobalString(AncientFlag.Name)
}
Expand Down Expand Up @@ -2440,7 +2457,7 @@ func SplitTagsFlag(tagsFlag string) map[string]string {
func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.Database {
var (
cache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
handles = MakeDatabaseHandles()
handles = MakeDatabaseHandles(ctx.GlobalInt(FDLimitFlag.Name))

err error
chainDb ethdb.Database
Expand Down
4 changes: 3 additions & 1 deletion consensus/istanbul/ibft/core/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package core

import (
"reflect"

"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/istanbul"
istanbulcommon "github.com/ethereum/go-ethereum/consensus/istanbul/common"
Expand All @@ -35,6 +35,7 @@ func (c *core) sendCommitForOldBlock(view *istanbul.View, digest common.Hash) {
View: view,
Digest: digest,
}
c.logger.Debug(fmt.Sprintf("=====> Sending commmit for old block, address: %v, hash: %v, block round: %v, block sequence: %v", c.Address(), digest, view.Round, view.Sequence))
c.broadcastCommit(sub)
}

Expand Down Expand Up @@ -76,6 +77,7 @@ func (c *core) handleCommit(msg *ibfttypes.Message, src istanbul.Validator) erro
// by committing the proposal without PREPARE messages.
if c.current.Commits.Size() >= c.QuorumSize() && c.state.Cmp(ibfttypes.StateCommitted) < 0 {
// Still need to call LockHash here since state can skip Prepared state and jump directly to the Committed state.
c.logger.Debug(fmt.Sprintf("=====> Committing to a proposal and locking hash due to 2f+1 commits msgs, address: %v, hash: %v, state: %v", c.Address(), commit.Digest, c.state.String()))
c.current.LockHash()
c.commit()
}
Expand Down
7 changes: 6 additions & 1 deletion consensus/istanbul/ibft/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"math/big"
"sync"
"time"

"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/istanbul"
ibfttypes "github.com/ethereum/go-ethereum/consensus/istanbul/ibft/types"
Expand Down Expand Up @@ -264,6 +264,8 @@ func (c *core) startNewRound(round *big.Int) {
c.sendPreprepare(r)
} else if c.current.pendingRequest != nil {
c.sendPreprepare(c.current.pendingRequest)
} else {
logger.Info("=====> No locked proposal and pending request")
}
}
c.newRoundChangeTimer()
Expand Down Expand Up @@ -292,11 +294,14 @@ func (c *core) updateRoundState(view *istanbul.View, validatorSet istanbul.Valid
// Lock only if both roundChange is true and it is locked
if roundChange && c.current != nil {
if c.current.IsHashLocked() {
c.logger.Debug(fmt.Sprintf("=====> Setting new round state with locked hash: %v, and pending request", c.current.GetLockedHash()))
c.current = newRoundState(view, validatorSet, c.current.GetLockedHash(), c.current.Preprepare, c.current.pendingRequest, c.backend.HasBadProposal)
} else {
c.logger.Debug(fmt.Sprintf("=====> Setting new round state with pending request"))
c.current = newRoundState(view, validatorSet, common.Hash{}, nil, c.current.pendingRequest, c.backend.HasBadProposal)
}
} else {
c.logger.Debug(fmt.Sprintf("=====> Setting new round state with no pending request"))
c.current = newRoundState(view, validatorSet, common.Hash{}, nil, nil, c.backend.HasBadProposal)
}
}
Expand Down
2 changes: 2 additions & 0 deletions consensus/istanbul/ibft/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/istanbul"
istanbulcommon "github.com/ethereum/go-ethereum/consensus/istanbul/common"
Expand Down Expand Up @@ -194,6 +195,7 @@ func (c *core) handleTimeoutMsg() {
if !c.waitingForRoundChange {
maxRound := c.roundChangeSet.MaxRound(c.valSet.F() + 1)
if maxRound != nil && maxRound.Cmp(c.current.Round()) > 0 {
c.logger.Info(fmt.Sprintf("=====>catching up to max round, calling sendRoundChange. max round - %v, current round - %v, seq - %v", maxRound, c.current.Round(), c.current.Sequence()))
c.sendRoundChange(maxRound)
return
}
Expand Down
5 changes: 3 additions & 2 deletions consensus/istanbul/ibft/core/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ package core

import (
"reflect"

"fmt"
"github.com/ethereum/go-ethereum/consensus/istanbul"
istanbulcommon "github.com/ethereum/go-ethereum/consensus/istanbul/common"
ibfttypes "github.com/ethereum/go-ethereum/consensus/istanbul/ibft/types"
)

func (c *core) sendPrepare() {
logger := c.logger.New("state", c.state)

sub := c.current.Subject()
encodedSubject, err := ibfttypes.Encode(sub)
if err != nil {
logger.Error("Failed to encode", "subject", sub)
return
}
logger.Debug(fmt.Sprintf("=====>Broadcast Prepare, address: %v", c.Address()))
c.broadcast(&ibfttypes.Message{
Code: ibfttypes.MsgPrepare,
Msg: encodedSubject,
Expand Down Expand Up @@ -63,6 +63,7 @@ func (c *core) handlePrepare(msg *ibfttypes.Message, src istanbul.Validator) err
// and we are in earlier state before Prepared state.
if ((c.current.IsHashLocked() && prepare.Digest == c.current.GetLockedHash()) || c.current.GetPrepareOrCommitSize() >= c.QuorumSize()) &&
c.state.Cmp(ibfttypes.StatePrepared) < 0 {
c.logger.Debug(fmt.Sprintf("=====>Prepared, due to 2f+1 prepare or commit msgs, address: %v", c.Address()))
c.current.LockHash()
c.setState(ibfttypes.StatePrepared)
c.sendCommit()
Expand Down
6 changes: 5 additions & 1 deletion consensus/istanbul/ibft/core/preprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package core

import (
"time"

"fmt"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/istanbul"
istanbulcommon "github.com/ethereum/go-ethereum/consensus/istanbul/common"
Expand All @@ -38,6 +38,7 @@ func (c *core) sendPreprepare(request *istanbul.Request) {
logger.Error("Failed to encode", "view", curView)
return
}
logger.Debug(fmt.Sprintf("=====> Broadcast preprepare, address: %v", c.Address()))
c.broadcast(&ibfttypes.Message{
Code: ibfttypes.MsgPreprepare,
Msg: preprepare,
Expand Down Expand Up @@ -105,17 +106,20 @@ func (c *core) handlePreprepare(msg *ibfttypes.Message, src istanbul.Validator)
if c.current.IsHashLocked() {
if preprepare.Proposal.Hash() == c.current.GetLockedHash() {
// Broadcast COMMIT and enters Prepared state directly
logger.Debug(fmt.Sprintf("=====> Prepared, preprepare proposal == locked hash, address: %v, hash: %v", c.Address(), c.current.Proposal()))
c.acceptPreprepare(preprepare)
c.setState(ibfttypes.StatePrepared)
c.sendCommit()
} else {
// Send round change
logger.Info(fmt.Sprintf("====>Pre-prepare: proposed hash not matching current locked hash. round - %v, seq - %v", c.current.Round(), c.current.Sequence()))
c.sendNextRoundChange()
}
} else {
// Either
// 1. the locked proposal and the received proposal match
// 2. we have no locked proposal
logger.Debug(fmt.Sprintf("=====> Prepared, no locked proposal, address: %v", c.Address()))
c.acceptPreprepare(preprepare)
c.setState(ibfttypes.StatePreprepared)
c.sendPrepare()
Expand Down
2 changes: 2 additions & 0 deletions consensus/istanbul/ibft/core/roundchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"fmt"
"math/big"
"sync"

Expand Down Expand Up @@ -92,6 +93,7 @@ func (c *core) handleRoundChange(msg *ibfttypes.Message, src istanbul.Validator)
return err
}

logger.Debug(fmt.Sprintf("=====> Handling round change msg, current round: %v, current sequence: %v, total number of round change msg for the round %v, sequence %v, is %v, waiting for round change? %v, current F() is %v", cv.Round, cv.Sequence, roundView.Round, roundView.Sequence, num, c.waitingForRoundChange, c.valSet.F()))
// Once we received f+1 ROUND CHANGE messages, those messages form a weak certificate.
// If our round number is smaller than the certificate's round number, we would
// try to catch up the round number.
Expand Down
30 changes: 11 additions & 19 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package console

import (
"context"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -354,26 +353,19 @@ func (c *Console) Welcome() {

// Get the consensus mechanism that is in use
func (c *Console) getConsensus() string {

var nodeInfo struct {
Protocols struct {
Eth struct { // only partial of eth/handler.go#NodeInfo
Consensus string
}
Istanbul struct { // a bit different from others
Consensus string
}
if apis, err := c.client.SupportedModules(); err == nil {
_, raft := apis["raft"]
if raft {
return "raft"
}
_, ibft := apis["istanbul"]
if ibft {
return "istanbul"
}
return "ethhash"
}

if err := c.client.CallContext(context.Background(), &nodeInfo, "admin_nodeInfo"); err != nil {
_, _ = fmt.Fprintf(c.printer, "WARNING: call to admin.getNodeInfo() failed, unable to determine consensus mechanism\n")
return "unknown"
}
if nodeInfo.Protocols.Istanbul.Consensus != "" {
return nodeInfo.Protocols.Istanbul.Consensus
}
return nodeInfo.Protocols.Eth.Consensus
_, _ = fmt.Fprintf(c.printer, "WARNING: call to rpc_modules() failed, unable to determine consensus mechanism\n")
return "unknown"
}

// Evaluate executes code and pretty prints the result to the specified output
Expand Down
1 change: 0 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
ReturnData: nil,
}, nil
}

ret, leftoverGas, vmerr = evm.Call(sender, to, data, st.gas, st.value)
}
if vmerr != nil {
Expand Down
1 change: 1 addition & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ func (pool *TxPool) addTxs(txs []*types.Transaction, local, sync bool) []error {
errs[nilSlot] = err
nilSlot++
}
log.Trace("Filtered transactions with errors", "count", len(errs))
// Reorg the pool internals if needed and return
done := pool.requestPromoteExecutables(dirtyAddrs)
if sync {
Expand Down
2 changes: 1 addition & 1 deletion eth/protocols/eth/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *Peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis

// TD at mainnet block #7753254 is 76 bits. If it becomes 100 million times
// larger, it will still fit within 100 bits
if tdlen := p.td.BitLen(); tdlen > 100 {
if tdlen := p.td.BitLen(); tdlen > 200 {
return fmt.Errorf("too large total difficulty: bitlen %d", tdlen)
}
return nil
Expand Down
Loading