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

Add configurable threshold for 'future block' check #800

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6cd2989
Add allowedFutureBlockTime flag for Istanbul.
SatpalSandhu61 Aug 7, 2019
430818f
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Aug 13, 2019
e0482b5
Merge branch 'master' of https://github.com/jpmorganchase/quorum into…
SatpalSandhu61 Aug 13, 2019
ae29956
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Aug 28, 2019
b735774
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Sep 19, 2019
39f8e20
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Oct 1, 2019
a4dbaf3
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Oct 2, 2019
82ab68c
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Oct 7, 2019
b53f7cc
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Nov 11, 2019
3754202
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Nov 21, 2019
e69f611
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Jan 13, 2020
0c6a29d
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Jan 30, 2020
0b12e0b
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Mar 6, 2020
3cac171
Merge branch 'issue-792-add-allowedFutureBlockTime' of https://github…
SatpalSandhu61 Mar 12, 2020
74b7c95
Change flag description to match comment in upstream
SatpalSandhu61 Mar 17, 2020
769934e
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Mar 17, 2020
32cdcae
Make flag generic, so it also applies to Clique.
SatpalSandhu61 Mar 20, 2020
b5cb5a3
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
SatpalSandhu61 Mar 20, 2020
fb4ab53
Merge remote-tracking branch 'origin/issue-792-add-allowedFutureBlock…
SatpalSandhu61 Mar 20, 2020
02ecbfc
Merge branch 'master' into issue-792-add-allowedFutureBlockTime
jpmsam Apr 8, 2020
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 @@ -149,6 +149,7 @@ var (
utils.PluginSkipVerifyFlag,
utils.PluginLocalVerifyFlag,
utils.PluginPublicKeyFlag,
utils.AllowedFutureBlockTimeFlag,
// End-Quorum
}

Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.PluginSkipVerifyFlag,
utils.PluginLocalVerifyFlag,
utils.PluginPublicKeyFlag,
utils.AllowedFutureBlockTimeFlag,
},
},
{
Expand Down
7 changes: 7 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ var (
Name: "permissioned",
Usage: "If enabled, the node will allow only a defined list of nodes to connect",
}
AllowedFutureBlockTimeFlag = cli.Uint64Flag{
Name: "allowedfutureblocktime",
Usage: "Max time (in seconds) from current time allowed for blocks, before they're considered future blocks",
Value: 0,
}
// Plugins settings
PluginSettingsFlag = cli.StringFlag{
Name: "plugins",
Expand Down Expand Up @@ -1270,6 +1275,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
setEthash(ctx, cfg)
setIstanbul(ctx, cfg)

cfg.AllowedFutureBlockTime = ctx.GlobalUint64(AllowedFutureBlockTimeFlag.Name) //Quorum

if ctx.GlobalIsSet(SyncModeFlag.Name) {
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
}
Expand Down
5 changes: 3 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ func (c *Clique) verifyHeader(chain consensus.ChainReader, header *types.Header,
}
number := header.Number.Uint64()

// Don't waste time checking blocks from the future
if header.Time.Cmp(big.NewInt(time.Now().Unix())) > 0 {
// Don't waste time checking blocks from the future (adjusting for allowed threshold)
adjustedTimeNow := time.Now().Add(time.Duration(c.config.AllowedFutureBlockTime) * time.Second).Unix()
if header.Time.Cmp(big.NewInt(adjustedTimeNow)) > 0 {
return consensus.ErrFutureBlock
}
// Checkpoint blocks need to enforce zero beneficiary
Expand Down
9 changes: 5 additions & 4 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/istanbul"
"github.com/ethereum/go-ethereum/consensus/istanbul/validator"
istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core"
"github.com/ethereum/go-ethereum/consensus/istanbul/validator"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/sha3"
Expand Down Expand Up @@ -144,8 +144,9 @@ func (sb *backend) verifyHeader(chain consensus.ChainReader, header *types.Heade
return errUnknownBlock
}

// Don't waste time checking blocks from the future
if header.Time.Cmp(big.NewInt(now().Unix())) > 0 {
// Don't waste time checking blocks from the future (adjusting for allowed threshold)
adjustedTimeNow := now().Add(time.Duration(sb.config.AllowedFutureBlockTime) * time.Second).Unix()
if header.Time.Cmp(big.NewInt(adjustedTimeNow)) > 0 {
return consensus.ErrFutureBlock
}

Expand Down Expand Up @@ -308,7 +309,7 @@ func (sb *backend) verifyCommittedSeals(chain consensus.ChainReader, header *typ
return errInvalidCommittedSeals
}

// The length of validSeal should be larger than number of faulty node + 1
// The length of validSeal should be larger than number of faulty node + 1
if validSeal <= snap.ValSet.F() {
return errInvalidCommittedSeals
}
Expand Down
12 changes: 12 additions & 0 deletions consensus/istanbul/backend/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ func TestVerifyHeader(t *testing.T) {
t.Errorf("error mismatch: have %v, want %v", err, consensus.ErrFutureBlock)
}

// future block which is within AllowedFutureBlockTime
block = makeBlockWithoutSeal(chain, engine, chain.Genesis())
header = block.Header()
header.Time = new(big.Int).Add(big.NewInt(now().Unix()), new(big.Int).SetUint64(10))
priorValue := engine.config.AllowedFutureBlockTime
engine.config.AllowedFutureBlockTime = 10
err = engine.VerifyHeader(chain, header, false)
engine.config.AllowedFutureBlockTime = priorValue //restore changed value
if err == consensus.ErrFutureBlock {
t.Errorf("error mismatch: have %v, want nil", err)
}

// invalid nonce
block = makeBlockWithoutSeal(chain, engine, chain.Genesis())
header = block.Header()
Expand Down
22 changes: 12 additions & 10 deletions consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ const (
)

type Config struct {
RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
ProposerPolicy ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
Ceil2Nby3Block *big.Int `toml:",omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
RequestTimeout uint64 `toml:",omitempty"` // The timeout for each Istanbul round in milliseconds.
BlockPeriod uint64 `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
ProposerPolicy ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
Epoch uint64 `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
Ceil2Nby3Block *big.Int `toml:",omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
AllowedFutureBlockTime uint64 `toml:",omitempty"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
}

var DefaultConfig = &Config{
RequestTimeout: 10000,
BlockPeriod: 1,
ProposerPolicy: RoundRobin,
Epoch: 30000,
Ceil2Nby3Block: big.NewInt(0),
RequestTimeout: 10000,
BlockPeriod: 1,
ProposerPolicy: RoundRobin,
Epoch: 30000,
Ceil2Nby3Block: big.NewInt(0),
AllowedFutureBlockTime: 0,
}
2 changes: 2 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data
func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainConfig, config *Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
if chainConfig.Clique != nil {
chainConfig.Clique.AllowedFutureBlockTime = config.AllowedFutureBlockTime //Quorum
return clique.New(chainConfig.Clique, db)
}
// If Istanbul is requested, set it up
Expand All @@ -259,6 +260,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo
}
config.Istanbul.ProposerPolicy = istanbul.ProposerPolicy(chainConfig.Istanbul.ProposerPolicy)
config.Istanbul.Ceil2Nby3Block = chainConfig.Istanbul.Ceil2Nby3Block
config.Istanbul.AllowedFutureBlockTime = config.AllowedFutureBlockTime

return istanbulBackend.New(&config.Istanbul, ctx.NodeKey(), db)
}
Expand Down
3 changes: 2 additions & 1 deletion eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ type Config struct {
Istanbul istanbul.Config

// Miscellaneous options
DocRoot string `toml:"-"`
DocRoot string `toml:"-"`
AllowedFutureBlockTime uint64 //Quorum

// Type of the EWASM interpreter ("" for default)
EWASMInterpreter string
Expand Down
12 changes: 6 additions & 6 deletions eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func TestNodeInfo(t *testing.T) {
}{
{"ethash", nil, nil, false},
{"raft", nil, nil, true},
{"istanbul", nil, &params.IstanbulConfig{1, 1, big.NewInt(0)}, false},
{"clique", &params.CliqueConfig{1, 1}, nil, false},
{"istanbul", nil, &params.IstanbulConfig{1, 1, big.NewInt(0), 0}, false},
{"clique", &params.CliqueConfig{1, 1, 0}, nil, false},
}

// Make sure anything we screw up is restored
Expand Down Expand Up @@ -285,10 +285,10 @@ func testGetBlockBodies(t *testing.T, protocol int) {
available []bool // Availability of explicitly requested blocks
expected int // Total number of existing blocks to expect
}{
{1, nil, nil, 1}, // A single random block should be retrievable
{10, nil, nil, 10}, // Multiple random blocks should be retrievable
{limit, nil, nil, limit}, // The maximum possible blocks should be retrievable
{limit + 1, nil, nil, limit}, // No more than the possible block count should be returned
{1, nil, nil, 1}, // A single random block should be retrievable
{10, nil, nil, 10}, // Multiple random blocks should be retrievable
{limit, nil, nil, limit}, // The maximum possible blocks should be retrievable
{limit + 1, nil, nil, limit}, // No more than the possible block count should be returned
{0, []common.Hash{pm.blockchain.Genesis().Hash()}, []bool{true}, 1}, // The genesis block should be retrievable
{0, []common.Hash{pm.blockchain.CurrentBlock().Hash()}, []bool{true}, 1}, // The chains head block should be retrievable
{0, []common.Hash{{}}, []bool{false}, 0}, // A non existent block should not be returned
Expand Down
15 changes: 9 additions & 6 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ type ChainConfig struct {
// Quorum
//
// QIP714Block implements the permissions related changes
QIP714Block *big.Int `json:"qip714Block,omitempty"`
QIP714Block *big.Int `json:"qip714Block,omitempty"`
MaxCodeSizeChangeBlock *big.Int `json:"maxCodeSizeChangeBlock,omitempty"`
}

Expand All @@ -209,8 +209,9 @@ func (c *EthashConfig) String() string {

// CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
type CliqueConfig struct {
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
AllowedFutureBlockTime uint64 `json:"allowedFutureBlockTime"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
}

// String implements the stringer interface, returning the consensus engine details.
Expand All @@ -220,9 +221,10 @@ func (c *CliqueConfig) String() string {

// IstanbulConfig is the consensus engine configs for Istanbul based sealing.
type IstanbulConfig struct {
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
ProposerPolicy uint64 `json:"policy"` // The policy for proposer selection
Ceil2Nby3Block *big.Int `json:"ceil2Nby3Block,omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
ProposerPolicy uint64 `json:"policy"` // The policy for proposer selection
Ceil2Nby3Block *big.Int `json:"ceil2Nby3Block,omitempty"` // Number of confirmations required to move from one state to next [2F + 1 to Ceil(2N/3)]
AllowedFutureBlockTime uint64 `json:"allowedFutureBlockTime"` // Max time (in seconds) from current time allowed for blocks, before they're considered future blocks
}

// String implements the stringer interface, returning the consensus engine details.
Expand Down Expand Up @@ -319,6 +321,7 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool {
func (c *ChainConfig) IsQIP714(num *big.Int) bool {
return isForked(c.QIP714Block, num)
}

// Quorum
//
// IsMaxCodeSizeChangeBlock returns whether num represents a block number max code size
Expand Down