Skip to content

Commit bac7831

Browse files
authored
Remove istanbul.v1 code (#1999)
* Remove v1 types * Add backlog tests (remove v1) * Remove v1 references from istanbul core core.go * Remove v1 code from handler & handler_test * remove v1 code from preprepare files * remove v1 code from roundchange files * Remove most of v1 code * Remove isConsensusFork * Remove all mentions to V2Block * Remove useless testing suite function
1 parent aa72756 commit bac7831

38 files changed

+170
-2590
lines changed

cmd/geth/config.go

-3
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
161161
if ctx.GlobalIsSet(utils.OverrideEHardforkFlag.Name) {
162162
cfg.Eth.OverrideEHardfork = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideEHardforkFlag.Name))
163163
}
164-
if ctx.GlobalIsSet(utils.OverrideV2IstanbulForkFlag.Name) {
165-
cfg.Eth.OverrideV2IstanbulFork = new(big.Int).SetUint64(ctx.GlobalUint64(utils.OverrideV2IstanbulForkFlag.Name))
166-
}
167164
backend, _ := utils.RegisterEthService(stack, &cfg.Eth)
168165

169166
// Configure GraphQL if requested

cmd/geth/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ var (
7373
utils.USBFlag,
7474
// utils.SmartCardDaemonPathFlag,
7575
utils.OverrideEHardforkFlag,
76-
utils.OverrideV2IstanbulForkFlag,
7776
utils.TxPoolLocalsFlag,
7877
utils.TxPoolNoLocalsFlag,
7978
utils.TxPoolJournalFlag,

cmd/utils/flags.go

-6
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ var (
241241
Usage: "Manually specify the espresso fork block, overriding the bundled setting",
242242
}
243243

244-
// V2 Istanbul fork activation overrides
245-
OverrideV2IstanbulForkFlag = cli.Uint64Flag{
246-
Name: "override.v2istanbul",
247-
Usage: "Manually specify the v2 istanbul consensus fork block, overriding the bundled setting",
248-
}
249-
250244
BloomFilterSizeFlag = cli.Uint64Flag{
251245
Name: "bloomfilter.size",
252246
Usage: "Megabytes of memory allocated to bloom-filter for pruning",

consensus/istanbul/config.go

-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package istanbul
1818

1919
import (
2020
"fmt"
21-
"math/big"
2221

2322
"github.com/celo-org/celo-blockchain/common"
2423
"github.com/celo-org/celo-blockchain/p2p/enode"
@@ -69,8 +68,6 @@ type Config struct {
6968
AnnounceAggressiveQueryEnodeGossipOnEnablement bool `toml:",omitempty"` // Specifies if this node should aggressively query enodes on announce enablement
7069
AnnounceAdditionalValidatorsToGossip int64 `toml:",omitempty"` // Specifies the number of additional non-elected validators to gossip an announce
7170

72-
V2Block *big.Int `toml:",omitempty"` // Activation block for the V2 istanbul consensus fork (nil = no fork, 0 = already activated)
73-
7471
// Load test config
7572
LoadTestCSVFile string `toml:",omitempty"` // If non-empty, specifies the file to write out csv metrics about the block production cycle to.
7673
}
@@ -107,9 +104,6 @@ var DefaultConfig = &Config{
107104

108105
//ApplyParamsChainConfigToConfig applies the istanbul config values from params.chainConfig to the istanbul.Config config
109106
func ApplyParamsChainConfigToConfig(chainConfig *params.ChainConfig, config *Config) error {
110-
if chainConfig.Istanbul.V2Block != nil {
111-
config.V2Block = chainConfig.Istanbul.V2Block
112-
}
113107
if chainConfig.Istanbul.Epoch != 0 {
114108
if chainConfig.Istanbul.Epoch < MinEpochSize {
115109
return fmt.Errorf("istanbul.Epoch must be greater than %d", MinEpochSize-1)

consensus/istanbul/core/backlog.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ import (
3030

3131
var (
3232
// msgPriority is defined for calculating processing priority to speedup consensus
33-
// istanbul.MsgPreprepare > istanbul.MsgCommit > istanbul.MsgPrepare
33+
// istanbul.MsgPreprepareV2 > istanbul.MsgCommit > istanbul.MsgPrepare
3434
msgPriority = map[uint64]int{
35-
istanbul.MsgPreprepare: 1,
3635
istanbul.MsgPreprepareV2: 1,
3736
istanbul.MsgCommit: 2,
3837
istanbul.MsgPrepare: 3,
@@ -328,16 +327,12 @@ func toPriority(msgCode uint64, view *istanbul.View) int64 {
328327

329328
func extractMessageView(msg *istanbul.Message) *istanbul.View {
330329
switch msg.Code {
331-
case istanbul.MsgPreprepare:
332-
return msg.Preprepare().View
333330
case istanbul.MsgPreprepareV2:
334331
return msg.PreprepareV2().View
335332
case istanbul.MsgPrepare:
336333
return msg.Prepare().View
337334
case istanbul.MsgCommit:
338335
return msg.Commit().Subject.View
339-
case istanbul.MsgRoundChange:
340-
return msg.RoundChange().View
341336
case istanbul.MsgRoundChangeV2:
342337
return &msg.RoundChangeV2().Request.View
343338
default:

consensus/istanbul/core/backlog_test.go

+35-28
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ func TestCheckMessage(t *testing.T) {
4343
current: newRoundState(&istanbul.View{
4444
Sequence: big.NewInt(2),
4545
Round: big.NewInt(2),
46-
}, valSet, valSet.GetByIndex(0), false),
46+
}, valSet, valSet.GetByIndex(0)),
4747
}
4848

4949
t.Run("invalid view format", func(t *testing.T) {
50-
err := c.checkMessage(istanbul.MsgPreprepare, nil)
50+
err := c.checkMessage(istanbul.MsgPreprepareV2, nil)
5151
if err != errInvalidMessage {
5252
t.Errorf("error mismatch: have %v, want %v", err, errInvalidMessage)
5353
}
5454
})
5555

5656
testStates := []State{StateAcceptRequest, StatePreprepared, StatePrepared, StateCommitted, StateWaitingForNewRound}
57-
testCodes := []uint64{istanbul.MsgPreprepare, istanbul.MsgPrepare, istanbul.MsgCommit, istanbul.MsgRoundChange}
57+
testCodes := []uint64{istanbul.MsgPreprepareV2, istanbul.MsgPrepare, istanbul.MsgCommit, istanbul.MsgRoundChangeV2}
5858

5959
// accept Commits from sequence, round matching LastSubject
6060
t.Run("Rejects all other older rounds", func(t *testing.T) {
@@ -116,7 +116,7 @@ func TestCheckMessage(t *testing.T) {
116116
for _, testCode := range testCodes {
117117
c.current.(*roundStateImpl).state = testState
118118
err := c.checkMessage(testCode, v)
119-
if testCode == istanbul.MsgRoundChange {
119+
if testCode == istanbul.MsgRoundChangeV2 {
120120
if err != nil {
121121
t.Errorf("error mismatch: have %v, want nil", err)
122122
}
@@ -133,11 +133,11 @@ func TestCheckMessage(t *testing.T) {
133133

134134
for _, testCode := range testCodes {
135135
err := c.checkMessage(testCode, v)
136-
if testCode == istanbul.MsgRoundChange {
136+
if testCode == istanbul.MsgRoundChangeV2 {
137137
if err != nil {
138138
t.Errorf("error mismatch: have %v, want nil", err)
139139
}
140-
} else if testCode == istanbul.MsgPreprepare {
140+
} else if testCode == istanbul.MsgPreprepareV2 {
141141
if err != nil {
142142
t.Errorf("error mismatch: have %v, want nil", err)
143143
}
@@ -154,7 +154,7 @@ func TestCheckMessage(t *testing.T) {
154154
c.current.(*roundStateImpl).state = StatePreprepared
155155
for _, testCode := range testCodes {
156156
err := c.checkMessage(testCode, v)
157-
if testCode == istanbul.MsgRoundChange {
157+
if testCode == istanbul.MsgRoundChangeV2 {
158158
if err != nil {
159159
t.Errorf("error mismatch: have %v, want nil", err)
160160
}
@@ -169,7 +169,7 @@ func TestCheckMessage(t *testing.T) {
169169
c.current.(*roundStateImpl).state = StatePrepared
170170
for _, testCode := range testCodes {
171171
err := c.checkMessage(testCode, v)
172-
if testCode == istanbul.MsgRoundChange {
172+
if testCode == istanbul.MsgRoundChangeV2 {
173173
if err != nil {
174174
t.Errorf("error mismatch: have %v, want nil", err)
175175
}
@@ -184,7 +184,7 @@ func TestCheckMessage(t *testing.T) {
184184
c.current.(*roundStateImpl).state = StateCommitted
185185
for _, testCode := range testCodes {
186186
err := c.checkMessage(testCode, v)
187-
if testCode == istanbul.MsgRoundChange {
187+
if testCode == istanbul.MsgRoundChangeV2 {
188188
if err != nil {
189189
t.Errorf("error mismatch: have %v, want nil", err)
190190
}
@@ -199,7 +199,7 @@ func TestCheckMessage(t *testing.T) {
199199
c.current.(*roundStateImpl).state = StateWaitingForNewRound
200200
for _, testCode := range testCodes {
201201
err := c.checkMessage(testCode, v)
202-
if testCode == istanbul.MsgRoundChange || testCode == istanbul.MsgPreprepare {
202+
if testCode == istanbul.MsgRoundChangeV2 || testCode == istanbul.MsgPreprepareV2 {
203203
if err != nil {
204204
t.Errorf("error mismatch: have %v, want nil", err)
205205
}
@@ -231,8 +231,8 @@ func TestStoreBacklog(t *testing.T) {
231231
p1 := validator.New(common.BytesToAddress([]byte("12345667890")), blscrypto.SerializedPublicKey{})
232232
p2 := validator.New(common.BytesToAddress([]byte("47324349949")), blscrypto.SerializedPublicKey{})
233233

234-
mPreprepare := istanbul.NewPreprepareMessage(
235-
&istanbul.Preprepare{View: v10, Proposal: makeBlock(10)},
234+
mPreprepare := istanbul.NewPreprepareV2Message(
235+
&istanbul.PreprepareV2{View: v10, Proposal: makeBlock(10)},
236236
p1.Address(),
237237
)
238238
backlog.store(mPreprepare)
@@ -246,8 +246,8 @@ func TestStoreBacklog(t *testing.T) {
246246
&istanbul.Subject{View: v10, Digest: common.BytesToHash([]byte("1234567890"))},
247247
p1.Address(),
248248
)
249-
mPreprepare2 := istanbul.NewPreprepareMessage(
250-
&istanbul.Preprepare{View: v11, Proposal: makeBlock(11)},
249+
mPreprepare2 := istanbul.NewPreprepareV2Message(
250+
&istanbul.PreprepareV2{View: v11, Proposal: makeBlock(11)},
251251
p2.Address(),
252252
)
253253

@@ -300,8 +300,8 @@ func TestClearBacklogForSequence(t *testing.T) {
300300
// The backlog's state is sequence number 1, round 0. Store future messages with sequence number 2
301301
p1 := validator.New(common.BytesToAddress([]byte("12345667890")), blscrypto.SerializedPublicKey{})
302302

303-
mPreprepare := istanbul.NewPreprepareMessage(
304-
&istanbul.Preprepare{
303+
mPreprepare := istanbul.NewPreprepareV2Message(
304+
&istanbul.PreprepareV2{
305305
View: &istanbul.View{Round: big.NewInt(0), Sequence: big.NewInt(2)},
306306
Proposal: makeBlock(2),
307307
},
@@ -360,15 +360,21 @@ func TestProcessFutureBacklog(t *testing.T) {
360360
backlog.store(mFuture)
361361

362362
// push a message from the past and check we expire it
363-
mPast := istanbul.NewRoundChangeMessage(&istanbul.RoundChange{
364-
View: &istanbul.View{
365-
Round: big.NewInt(0),
366-
Sequence: oldSequence,
367-
},
368-
PreparedCertificate: istanbul.PreparedCertificate{
369-
Proposal: makeBlock(0),
363+
addr := valSet.GetByIndex(1).Address()
364+
roundChangeV2 := &istanbul.RoundChangeV2{
365+
Request: istanbul.RoundChangeRequest{
366+
Address: addr,
367+
View: istanbul.View{
368+
Round: big.NewInt(0),
369+
Sequence: oldSequence,
370+
},
371+
PreparedCertificateV2: istanbul.PCV2FromPCV1(istanbul.PreparedCertificate{
372+
Proposal: makeBlock(0),
373+
}),
370374
},
371-
}, valSet.GetByIndex(1).Address())
375+
}
376+
// No need to sign the RoundChangeRequest for this test
377+
mPast := istanbul.NewRoundChangeV2Message(roundChangeV2, addr)
372378

373379
backlog.store(mPast)
374380

@@ -404,17 +410,18 @@ func TestProcessBacklog(t *testing.T) {
404410
address := common.BytesToAddress([]byte("0xce10ce10"))
405411

406412
msgs := []*istanbul.Message{
407-
istanbul.NewPreprepareMessage(
408-
&istanbul.Preprepare{View: v, Proposal: makeBlock(1)},
413+
istanbul.NewPreprepareV2Message(
414+
&istanbul.PreprepareV2{View: v, Proposal: makeBlock(1)},
409415
address,
410416
),
411417
istanbul.NewPrepareMessage(subject, address),
412418
istanbul.NewCommitMessage(
413419
&istanbul.CommittedSubject{Subject: subject, CommittedSeal: []byte{0x63, 0x65, 0x6C, 0x6F}},
414420
address,
415421
),
416-
istanbul.NewRoundChangeMessage(
417-
&istanbul.RoundChange{View: v, PreparedCertificate: istanbul.EmptyPreparedCertificate()},
422+
istanbul.NewRoundChangeV2Message(
423+
&istanbul.RoundChangeV2{
424+
Request: istanbul.RoundChangeRequest{View: *v}, PreparedProposal: makeBlock(1)},
418425
address,
419426
),
420427
}

consensus/istanbul/core/commit_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestHandleCommit(t *testing.T) {
5656
for i, backend := range sys.backends {
5757
c := backend.engine.(*core)
5858
// same view as the expected one to everyone
59-
c.current = newTestRoundState(
59+
c.current = newTestRoundStateV2(
6060
expectedSubject.View,
6161
backend.peers,
6262
)
@@ -80,13 +80,13 @@ func TestHandleCommit(t *testing.T) {
8080
c := backend.engine.(*core)
8181
if i == 0 {
8282
// replica 0 is the proposer
83-
c.current = newTestRoundState(
83+
c.current = newTestRoundStateV2(
8484
expectedSubject.View,
8585
backend.peers,
8686
)
8787
c.current.(*roundStateImpl).state = StatePreprepared
8888
} else {
89-
c.current = newTestRoundState(
89+
c.current = newTestRoundStateV2(
9090
&istanbul.View{
9191
Round: big.NewInt(0),
9292
// proposal from 1 round in the future
@@ -111,13 +111,13 @@ func TestHandleCommit(t *testing.T) {
111111

112112
if i == 0 {
113113
// replica 0 is the proposer
114-
c.current = newTestRoundState(
114+
c.current = newTestRoundStateV2(
115115
expectedSubject.View,
116116
backend.peers,
117117
)
118118
c.current.(*roundStateImpl).state = StatePreprepared
119119
} else {
120-
c.current = newTestRoundState(
120+
c.current = newTestRoundStateV2(
121121
&istanbul.View{
122122
Round: big.NewInt(0),
123123
// we're 2 blocks before so this is indeed a
@@ -141,7 +141,7 @@ func TestHandleCommit(t *testing.T) {
141141

142142
for i, backend := range sys.backends {
143143
c := backend.engine.(*core)
144-
c.current = newTestRoundState(
144+
c.current = newTestRoundStateV2(
145145
&istanbul.View{
146146
Round: big.NewInt(0),
147147
Sequence: proposal.Number(),
@@ -174,13 +174,13 @@ func TestHandleCommit(t *testing.T) {
174174
c := backend.engine.(*core)
175175
if i == 0 {
176176
// replica 0 is the proposer
177-
c.current = newTestRoundState(
177+
c.current = newTestRoundStateV2(
178178
expectedSubject.View,
179179
backend.peers,
180180
)
181181
c.current.(*roundStateImpl).state = StatePrepared
182182
} else {
183-
c.current = newTestRoundState(
183+
c.current = newTestRoundStateV2(
184184
&istanbul.View{
185185
Round: big.NewInt(1),
186186
Sequence: big.NewInt(0).Sub(proposal.Number(), common.Big1),
@@ -297,7 +297,7 @@ func TestVerifyCommit(t *testing.T) {
297297
Digest: newTestProposal().Hash(),
298298
},
299299
},
300-
roundState: newTestRoundState(
300+
roundState: newTestRoundStateV2(
301301
&istanbul.View{Round: big.NewInt(0), Sequence: big.NewInt(0)},
302302
valSet,
303303
),
@@ -311,7 +311,7 @@ func TestVerifyCommit(t *testing.T) {
311311
Digest: newTestProposal().Hash(),
312312
},
313313
},
314-
roundState: newTestRoundState(
314+
roundState: newTestRoundStateV2(
315315
&istanbul.View{Round: big.NewInt(1), Sequence: big.NewInt(1)},
316316
valSet,
317317
),
@@ -325,7 +325,7 @@ func TestVerifyCommit(t *testing.T) {
325325
Digest: common.BytesToHash([]byte("1234567890")),
326326
},
327327
},
328-
roundState: newTestRoundState(
328+
roundState: newTestRoundStateV2(
329329
&istanbul.View{Round: big.NewInt(1), Sequence: big.NewInt(1)},
330330
valSet,
331331
),
@@ -339,7 +339,7 @@ func TestVerifyCommit(t *testing.T) {
339339
Digest: newTestProposal().Hash(),
340340
},
341341
},
342-
roundState: newTestRoundState(
342+
roundState: newTestRoundStateV2(
343343
&istanbul.View{Round: big.NewInt(1), Sequence: big.NewInt(1)},
344344
valSet,
345345
),
@@ -353,7 +353,7 @@ func TestVerifyCommit(t *testing.T) {
353353
Digest: newTestProposal().Hash(),
354354
},
355355
},
356-
roundState: newTestRoundState(
356+
roundState: newTestRoundStateV2(
357357
&istanbul.View{Round: big.NewInt(0), Sequence: big.NewInt(0)},
358358
valSet,
359359
),
@@ -367,7 +367,7 @@ func TestVerifyCommit(t *testing.T) {
367367
Digest: newTestProposal().Hash(),
368368
},
369369
},
370-
roundState: newTestRoundState(
370+
roundState: newTestRoundStateV2(
371371
&istanbul.View{Round: big.NewInt(0), Sequence: big.NewInt(0)},
372372
valSet,
373373
),
@@ -404,7 +404,7 @@ func BenchmarkHandleCommit(b *testing.B) {
404404
for i, backend := range sys.backends {
405405
c := backend.engine.(*core)
406406
// same view as the expected one to everyone
407-
c.current = newTestRoundState(
407+
c.current = newTestRoundStateV2(
408408
expectedSubject.View,
409409
backend.peers,
410410
)

0 commit comments

Comments
 (0)