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 12 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 @@ -145,6 +145,7 @@ var (
utils.EmitCheckpointsFlag,
utils.IstanbulRequestTimeoutFlag,
utils.IstanbulBlockPeriodFlag,
utils.IstanbulAllowedFutureBlockTimeFlag,
utils.PluginSettingsFlag,
utils.PluginSkipVerifyFlag,
utils.PluginLocalVerifyFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ var AppHelpFlagGroups = []flagGroup{
Flags: []cli.Flag{
utils.IstanbulRequestTimeoutFlag,
utils.IstanbulBlockPeriodFlag,
utils.IstanbulAllowedFutureBlockTimeFlag,
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ var (
Usage: "Default minimum difference between two consecutive block's timestamps in seconds",
Value: eth.DefaultConfig.Istanbul.BlockPeriod,
}
IstanbulAllowedFutureBlockTimeFlag = cli.Uint64Flag{
Name: "istanbul.allowedfutureblocktime",
Usage: "Time threshold allowed when detecting future blocks in seconds",
trung marked this conversation as resolved.
Show resolved Hide resolved
Value: eth.DefaultConfig.Istanbul.AllowedFutureBlockTime,
}

// Metrics flags
MetricsEnabledFlag = cli.BoolFlag{
Expand Down Expand Up @@ -1201,6 +1206,9 @@ func setIstanbul(ctx *cli.Context, cfg *eth.Config) {
if ctx.GlobalIsSet(IstanbulBlockPeriodFlag.Name) {
cfg.Istanbul.BlockPeriod = ctx.GlobalUint64(IstanbulBlockPeriodFlag.Name)
}
if ctx.GlobalIsSet(IstanbulAllowedFutureBlockTimeFlag.Name) {
cfg.Istanbul.AllowedFutureBlockTime = ctx.GlobalUint64(IstanbulAllowedFutureBlockTimeFlag.Name)
}
}

// checkExclusive verifies that only a single instance of the provided flags was
Expand Down
5 changes: 3 additions & 2 deletions consensus/istanbul/backend/engine.go
Original file line number Diff line number Diff line change
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
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
12 changes: 7 additions & 5 deletions consensus/istanbul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ 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"` // Time threshold allowed when detecting future blocks, in seconds
}

var DefaultConfig = &Config{
Expand All @@ -39,4 +40,5 @@ var DefaultConfig = &Config{
ProposerPolicy: RoundRobin,
Epoch: 30000,
Ceil2Nby3Block: big.NewInt(0),
AllowedFutureBlockTime: 1,
}