-
Notifications
You must be signed in to change notification settings - Fork 843
Continuous Staking 0 - P-chain stakers property testing #1259
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
Changes from 1 commit
4aed100
94ddc25
43cf22a
d0ea2a0
245fa58
2e9fd5f
cbd246b
e7691da
94ecc46
cf91599
382148d
8c119d5
0e48267
3bead39
f6356f2
13c5256
610b14d
0c6064a
ffc7e42
e8f6abe
343693f
f8eb5c3
8441a3a
6958914
a924b94
7d6fda1
5a57560
4be61bb
45cab8a
4173c34
fbd5048
b3a2fad
d6a65e6
1f32388
30ac9cb
cd5cd2b
adc5f40
ab56c7f
643e3b2
9c4fa9a
c47b72a
06bbc5d
be9a042
273cab4
2acb7ef
8030940
ff98262
68dd0f5
c63f3b5
1e104db
d6d0a83
e8ad209
7ef586d
7c69f5e
42bf741
b50c595
1229d7c
8f7d5b2
33b7dd9
340b25c
2a57245
40719d9
054a4d2
92db303
5725cbc
e2f4922
6604f38
c5941a8
99041e5
c47f410
b6b8e9f
8177cd0
59de7f1
73a8117
6253862
5fbeab9
628b5c6
07fdd6f
564098a
4ed0ec6
79f78c2
e28dc21
93eb13e
157bc5f
8ff47f5
afb6296
f3281bc
4929d31
52319b2
1a136c5
c220b51
8fcfb76
940dbe3
1c5de0c
44ed635
62ab0b5
90bbe95
6ac3131
bae62c9
9a3e581
d5177d9
f006058
ddb8cdb
55587c8
c85f8c1
aa5e002
10ac9cb
4a8d459
f3a9949
122ae78
cf49870
9f38091
87abc10
5ad376f
adac490
b0fc46d
00d63f9
24aa9ca
fe720f6
c1216ab
eecf423
c2c6bc4
ae79f52
599ebaa
7cd0606
fd32154
b5fa9a3
3cbf840
31c680a
2f43c45
84669e6
e4d9f04
0300469
10f6c52
b4346f7
d57e692
460046e
2cac774
801e2ea
2255c6e
acd1e7f
0427428
d744fbf
3c88bb7
c3750f3
879e2b6
9b9f802
4392421
267bd34
f5cb8ab
0c51db3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,80 +56,6 @@ func TestStateAndDiffComparisonToStorageModel(t *testing.T) { | |
| properties.TestingRun(t) | ||
| } | ||
|
|
||
| type sysUnderTest struct { | ||
| diffBlkIDSeed uint64 | ||
| baseDB database.Database | ||
| baseState State | ||
| sortedDiffIDs []ids.ID | ||
| diffsMap map[ids.ID]Diff | ||
| } | ||
|
|
||
| func newSysUnderTest(baseDB database.Database, baseState State) *sysUnderTest { | ||
| sys := &sysUnderTest{ | ||
| baseDB: baseDB, | ||
| baseState: baseState, | ||
| diffsMap: map[ids.ID]Diff{}, | ||
| sortedDiffIDs: []ids.ID{}, | ||
| } | ||
| return sys | ||
| } | ||
|
|
||
| func (s *sysUnderTest) GetState(blkID ids.ID) (Chain, bool) { | ||
| if state, found := s.diffsMap[blkID]; found { | ||
| return state, found | ||
| } | ||
| return s.baseState, blkID == s.baseState.GetLastAccepted() | ||
| } | ||
|
|
||
| func (s *sysUnderTest) addDiffOnTop() error { | ||
| newTopBlkID := ids.Empty.Prefix(atomic.AddUint64(&s.diffBlkIDSeed, 1)) | ||
| var topBlkID ids.ID | ||
| if len(s.sortedDiffIDs) == 0 { | ||
| topBlkID = s.baseState.GetLastAccepted() | ||
| } else { | ||
| topBlkID = s.sortedDiffIDs[len(s.sortedDiffIDs)-1] | ||
| } | ||
| newTopDiff, err := NewDiff(topBlkID, s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| s.sortedDiffIDs = append(s.sortedDiffIDs, newTopBlkID) | ||
| s.diffsMap[newTopBlkID] = newTopDiff | ||
| return nil | ||
| } | ||
|
|
||
| // getTopChainState returns top diff or baseState | ||
| func (s *sysUnderTest) getTopChainState() Chain { | ||
| var topChainStateID ids.ID | ||
| if len(s.sortedDiffIDs) != 0 { | ||
| topChainStateID = s.sortedDiffIDs[len(s.sortedDiffIDs)-1] | ||
| } else { | ||
| topChainStateID = s.baseState.GetLastAccepted() | ||
| } | ||
|
|
||
| topChainState, _ := s.GetState(topChainStateID) | ||
| return topChainState | ||
| } | ||
|
|
||
| // flushBottomDiff applies bottom diff if available | ||
| func (s *sysUnderTest) flushBottomDiff() (bool, error) { | ||
| if len(s.sortedDiffIDs) == 0 { | ||
| return false, nil | ||
| } | ||
| bottomDiffID := s.sortedDiffIDs[0] | ||
| diffToApply := s.diffsMap[bottomDiffID] | ||
|
|
||
| err := diffToApply.Apply(s.baseState) | ||
| if err != nil { | ||
| return true, err | ||
| } | ||
| s.baseState.SetLastAccepted(bottomDiffID) | ||
|
|
||
| s.sortedDiffIDs = s.sortedDiffIDs[1:] | ||
| delete(s.diffsMap, bottomDiffID) | ||
| return true, nil | ||
| } | ||
|
|
||
| // stakersCommands creates/destroy the system under test and generates | ||
| // commands and initial states (stakersStorageModel) | ||
| var stakersCommands = &commands.ProtoCommands{ | ||
|
|
@@ -926,3 +852,77 @@ func checkValidatorSetContent(res commands.Result) bool { | |
| } | ||
| return true | ||
| } | ||
|
|
||
| type sysUnderTest struct { | ||
| diffBlkIDSeed uint64 | ||
| baseDB database.Database | ||
| baseState State | ||
| sortedDiffIDs []ids.ID | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. queue of diff id in the order they are created. Recall that diffs are processed in FIFO order: created on top, consumed at the bottom (when applied to baseState) |
||
| diffsMap map[ids.ID]Diff | ||
| } | ||
|
|
||
| func newSysUnderTest(baseDB database.Database, baseState State) *sysUnderTest { | ||
| sys := &sysUnderTest{ | ||
| baseDB: baseDB, | ||
| baseState: baseState, | ||
| diffsMap: map[ids.ID]Diff{}, | ||
| sortedDiffIDs: []ids.ID{}, | ||
| } | ||
| return sys | ||
| } | ||
|
|
||
| func (s *sysUnderTest) GetState(blkID ids.ID) (Chain, bool) { | ||
| if state, found := s.diffsMap[blkID]; found { | ||
| return state, found | ||
| } | ||
| return s.baseState, blkID == s.baseState.GetLastAccepted() | ||
| } | ||
|
|
||
| func (s *sysUnderTest) addDiffOnTop() error { | ||
| newTopBlkID := ids.Empty.Prefix(atomic.AddUint64(&s.diffBlkIDSeed, 1)) | ||
| var topBlkID ids.ID | ||
| if len(s.sortedDiffIDs) == 0 { | ||
| topBlkID = s.baseState.GetLastAccepted() | ||
| } else { | ||
| topBlkID = s.sortedDiffIDs[len(s.sortedDiffIDs)-1] | ||
| } | ||
| newTopDiff, err := NewDiff(topBlkID, s) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| s.sortedDiffIDs = append(s.sortedDiffIDs, newTopBlkID) | ||
| s.diffsMap[newTopBlkID] = newTopDiff | ||
| return nil | ||
| } | ||
|
|
||
| // getTopChainState returns top diff or baseState | ||
| func (s *sysUnderTest) getTopChainState() Chain { | ||
| var topChainStateID ids.ID | ||
| if len(s.sortedDiffIDs) != 0 { | ||
| topChainStateID = s.sortedDiffIDs[len(s.sortedDiffIDs)-1] | ||
| } else { | ||
| topChainStateID = s.baseState.GetLastAccepted() | ||
| } | ||
|
|
||
| topChainState, _ := s.GetState(topChainStateID) | ||
| return topChainState | ||
| } | ||
|
|
||
| // flushBottomDiff applies bottom diff if available | ||
| func (s *sysUnderTest) flushBottomDiff() (bool, error) { | ||
| if len(s.sortedDiffIDs) == 0 { | ||
| return false, nil | ||
| } | ||
| bottomDiffID := s.sortedDiffIDs[0] | ||
| diffToApply := s.diffsMap[bottomDiffID] | ||
|
|
||
| err := diffToApply.Apply(s.baseState) | ||
| if err != nil { | ||
| return true, err | ||
| } | ||
| s.baseState.SetLastAccepted(bottomDiffID) | ||
|
|
||
| s.sortedDiffIDs = s.sortedDiffIDs[1:] | ||
| delete(s.diffsMap, bottomDiffID) | ||
|
Comment on lines
+990
to
+991
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drop applied diff |
||
| return true, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In prodc code, a diff is created when processing a block and each diff is identified by the blockID. In this test we dont' use blocks;
diffBlkIDSeedis a seed used to create unique ids for our diffs