@@ -24,32 +24,71 @@ import (
24
24
func TestPruneInvalid (t * testing.T ) {
25
25
tests := []struct {
26
26
root [32 ]byte // the root of the new INVALID block
27
+ payload [32 ]byte // the last valid hash
27
28
wantedNodeNumber int
28
29
wantedRoots [][32 ]byte
29
30
}{
30
31
{
31
32
[32 ]byte {'j' },
33
+ [32 ]byte {'B' },
32
34
12 ,
33
35
[][32 ]byte {[32 ]byte {'j' }},
34
36
},
35
37
{
36
38
[32 ]byte {'c' },
39
+ [32 ]byte {'B' },
37
40
4 ,
38
41
[][32 ]byte {[32 ]byte {'f' }, [32 ]byte {'e' }, [32 ]byte {'i' }, [32 ]byte {'h' }, [32 ]byte {'l' },
39
42
[32 ]byte {'k' }, [32 ]byte {'g' }, [32 ]byte {'d' }, [32 ]byte {'c' }},
40
43
},
41
44
{
42
45
[32 ]byte {'i' },
46
+ [32 ]byte {'H' },
43
47
12 ,
44
48
[][32 ]byte {[32 ]byte {'i' }},
45
49
},
46
50
{
47
51
[32 ]byte {'h' },
52
+ [32 ]byte {'G' },
48
53
11 ,
49
54
[][32 ]byte {[32 ]byte {'i' }, [32 ]byte {'h' }},
50
55
},
51
56
{
52
57
[32 ]byte {'g' },
58
+ [32 ]byte {'D' },
59
+ 8 ,
60
+ [][32 ]byte {[32 ]byte {'i' }, [32 ]byte {'h' }, [32 ]byte {'l' }, [32 ]byte {'k' }, [32 ]byte {'g' }},
61
+ },
62
+ {
63
+ [32 ]byte {'i' },
64
+ [32 ]byte {'D' },
65
+ 8 ,
66
+ [][32 ]byte {[32 ]byte {'i' }, [32 ]byte {'h' }, [32 ]byte {'l' }, [32 ]byte {'k' }, [32 ]byte {'g' }},
67
+ },
68
+ {
69
+ [32 ]byte {'f' },
70
+ [32 ]byte {'D' },
71
+ 11 ,
72
+ [][32 ]byte {[32 ]byte {'f' }, [32 ]byte {'e' }},
73
+ },
74
+ {
75
+ [32 ]byte {'h' },
76
+ [32 ]byte {'C' },
77
+ 5 ,
78
+ [][32 ]byte {
79
+ [32 ]byte {'f' },
80
+ [32 ]byte {'e' },
81
+ [32 ]byte {'i' },
82
+ [32 ]byte {'h' },
83
+ [32 ]byte {'l' },
84
+ [32 ]byte {'k' },
85
+ [32 ]byte {'g' },
86
+ [32 ]byte {'d' },
87
+ },
88
+ },
89
+ {
90
+ [32 ]byte {'g' },
91
+ [32 ]byte {'E' },
53
92
8 ,
54
93
[][32 ]byte {[32 ]byte {'i' }, [32 ]byte {'h' }, [32 ]byte {'l' }, [32 ]byte {'k' }, [32 ]byte {'g' }},
55
94
},
@@ -58,22 +97,45 @@ func TestPruneInvalid(t *testing.T) {
58
97
ctx := context .Background ()
59
98
f := setup (1 , 1 )
60
99
61
- require .NoError (t , f .InsertOptimisticBlock (ctx , 100 , [32 ]byte {'a' }, params .BeaconConfig ().ZeroHash , params . BeaconConfig (). ZeroHash , 1 , 1 ))
62
- require .NoError (t , f .InsertOptimisticBlock (ctx , 101 , [32 ]byte {'b' }, [32 ]byte {'a' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
63
- require .NoError (t , f .InsertOptimisticBlock (ctx , 102 , [32 ]byte {'c' }, [32 ]byte {'b' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
64
- require .NoError (t , f .InsertOptimisticBlock (ctx , 102 , [32 ]byte {'j' }, [32 ]byte {'b' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
65
- require .NoError (t , f .InsertOptimisticBlock (ctx , 103 , [32 ]byte {'d' }, [32 ]byte {'c' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
66
- require .NoError (t , f .InsertOptimisticBlock (ctx , 104 , [32 ]byte {'e' }, [32 ]byte {'d' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
67
- require .NoError (t , f .InsertOptimisticBlock (ctx , 104 , [32 ]byte {'g' }, [32 ]byte {'d' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
68
- require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'f' }, [32 ]byte {'e' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
69
- require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'h' }, [32 ]byte {'g' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
70
- require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'k' }, [32 ]byte {'g' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
71
- require .NoError (t , f .InsertOptimisticBlock (ctx , 106 , [32 ]byte {'i' }, [32 ]byte {'h' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
72
- require .NoError (t , f .InsertOptimisticBlock (ctx , 106 , [32 ]byte {'l' }, [32 ]byte {'k' }, params . BeaconConfig (). ZeroHash , 1 , 1 ))
100
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 100 , [32 ]byte {'a' }, params .BeaconConfig ().ZeroHash , [ 32 ] byte { 'A' } , 1 , 1 ))
101
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 101 , [32 ]byte {'b' }, [32 ]byte {'a' }, [ 32 ] byte { 'B' } , 1 , 1 ))
102
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 102 , [32 ]byte {'c' }, [32 ]byte {'b' }, [ 32 ] byte { 'C' } , 1 , 1 ))
103
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 102 , [32 ]byte {'j' }, [32 ]byte {'b' }, [ 32 ] byte { 'J' } , 1 , 1 ))
104
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 103 , [32 ]byte {'d' }, [32 ]byte {'c' }, [ 32 ] byte { 'D' } , 1 , 1 ))
105
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 104 , [32 ]byte {'e' }, [32 ]byte {'d' }, [ 32 ] byte { 'E' } , 1 , 1 ))
106
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 104 , [32 ]byte {'g' }, [32 ]byte {'d' }, [ 32 ] byte { 'G' } , 1 , 1 ))
107
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'f' }, [32 ]byte {'e' }, [ 32 ] byte { 'F' } , 1 , 1 ))
108
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'h' }, [32 ]byte {'g' }, [ 32 ] byte { 'H' } , 1 , 1 ))
109
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 105 , [32 ]byte {'k' }, [32 ]byte {'g' }, [ 32 ] byte { 'K' } , 1 , 1 ))
110
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 106 , [32 ]byte {'i' }, [32 ]byte {'h' }, [ 32 ] byte { 'I' } , 1 , 1 ))
111
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 106 , [32 ]byte {'l' }, [32 ]byte {'k' }, [ 32 ] byte { 'L' } , 1 , 1 ))
73
112
74
- roots , err := f .store .removeNode (context .Background (), tc .root )
113
+ roots , err := f .store .setOptimisticToInvalid (context .Background (), tc .root , tc . payload )
75
114
require .NoError (t , err )
76
115
require .DeepEqual (t , tc .wantedRoots , roots )
77
116
require .Equal (t , tc .wantedNodeNumber , f .NodeCount ())
78
117
}
79
118
}
119
+
120
+ // This is a regression test (10445)
121
+ func TestSetOptimisticToInvalid_ProposerBoost (t * testing.T ) {
122
+ ctx := context .Background ()
123
+ f := setup (1 , 1 )
124
+
125
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 100 , [32 ]byte {'a' }, params .BeaconConfig ().ZeroHash , [32 ]byte {'A' }, 1 , 1 ))
126
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 101 , [32 ]byte {'b' }, [32 ]byte {'a' }, [32 ]byte {'B' }, 1 , 1 ))
127
+ require .NoError (t , f .InsertOptimisticBlock (ctx , 101 , [32 ]byte {'c' }, [32 ]byte {'b' }, [32 ]byte {'C' }, 1 , 1 ))
128
+ f .store .proposerBoostLock .Lock ()
129
+ f .store .proposerBoostRoot = [32 ]byte {'c' }
130
+ f .store .previousProposerBoostScore = 10
131
+ f .store .previousProposerBoostRoot = [32 ]byte {'b' }
132
+ f .store .proposerBoostLock .Unlock ()
133
+
134
+ _ , err := f .SetOptimisticToInvalid (ctx , [32 ]byte {'c' }, [32 ]byte {'A' })
135
+ require .NoError (t , err )
136
+ f .store .proposerBoostLock .RLock ()
137
+ require .Equal (t , uint64 (0 ), f .store .previousProposerBoostScore )
138
+ require .DeepEqual (t , [32 ]byte {}, f .store .proposerBoostRoot )
139
+ require .DeepEqual (t , params .BeaconConfig ().ZeroHash , f .store .previousProposerBoostRoot )
140
+ f .store .proposerBoostLock .RUnlock ()
141
+ }
0 commit comments