@@ -19,26 +19,26 @@ func (f *ForkChoice) IsOptimistic(root [32]byte) (bool, error) {
19
19
return false , ErrUnknownNodeRoot
20
20
}
21
21
node := f .store .nodes [index ]
22
- return node .optimistic == SYNCING , nil
22
+ return node .optimistic == syncing , nil
23
23
}
24
24
25
25
// SetOptimisticToValid is called with the root of a block that was returned as
26
26
// VALID by the EL.
27
27
// WARNING: This method returns an error if the root is not found in forkchoice
28
28
func (f * ForkChoice ) SetOptimisticToValid (ctx context.Context , root [32 ]byte ) error {
29
- f .store .nodesLock .RLock ()
30
- defer f .store .nodesLock .RUnlock ()
29
+ f .store .nodesLock .Lock ()
30
+ defer f .store .nodesLock .Unlock ()
31
31
// We can only update if given root is in Fork Choice
32
32
index , ok := f .store .nodesIndices [root ]
33
33
if ! ok {
34
34
return ErrUnknownNodeRoot
35
35
}
36
36
37
- for node := f .store .nodes [index ]; node .optimistic == SYNCING ; node = f .store .nodes [index ] {
37
+ for node := f .store .nodes [index ]; node .optimistic == syncing ; node = f .store .nodes [index ] {
38
38
if ctx .Err () != nil {
39
39
return ctx .Err ()
40
40
}
41
- node .optimistic = VALID
41
+ node .optimistic = valid
42
42
index = node .parent
43
43
if index == NonExistentNode {
44
44
break
@@ -51,7 +51,7 @@ func (f *ForkChoice) SetOptimisticToValid(ctx context.Context, root [32]byte) er
51
51
// SetOptimisticToInvalid updates the synced_tips map when the block with the given root becomes INVALID.
52
52
// It takes two parameters: the root of the INVALID block and the payload Hash
53
53
// of the last valid block.s
54
- func (f * ForkChoice ) SetOptimisticToInvalid (ctx context.Context , root , payload [32 ]byte ) ([][32 ]byte , error ) {
54
+ func (f * ForkChoice ) SetOptimisticToInvalid (ctx context.Context , root , payloadHash [32 ]byte ) ([][32 ]byte , error ) {
55
55
f .store .nodesLock .Lock ()
56
56
invalidRoots := make ([][32 ]byte , 0 )
57
57
// We only support setting invalid a node existing in Forkchoice
@@ -62,7 +62,7 @@ func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, payload [
62
62
}
63
63
node := f .store .nodes [invalidIndex ]
64
64
65
- lastValidIndex , ok := f .store .payloadIndices [payload ]
65
+ lastValidIndex , ok := f .store .payloadIndices [payloadHash ]
66
66
if ! ok || lastValidIndex == NonExistentNode {
67
67
f .store .nodesLock .Unlock ()
68
68
return invalidRoots , errInvalidFinalizedNode
@@ -77,6 +77,8 @@ func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, payload [
77
77
}
78
78
node = f .store .nodes [firstInvalidIndex ]
79
79
}
80
+ // if the last valid hash is not an ancestor of the invalid block, we
81
+ // just remove the invalid block.
80
82
if node .parent != lastValidIndex {
81
83
node = f .store .nodes [invalidIndex ]
82
84
firstInvalidIndex = invalidIndex
@@ -120,7 +122,7 @@ func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, payload [
120
122
}
121
123
122
124
invalidIndices := map [uint64 ]bool {firstInvalidIndex : true }
123
- node .optimistic = INVALID
125
+ node .optimistic = invalid
124
126
node .weight = 0
125
127
delete (f .store .nodesIndices , node .root )
126
128
delete (f .store .canonicalNodes , node .root )
@@ -130,7 +132,7 @@ func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, payload [
130
132
if _ , ok := invalidIndices [invalidNode .parent ]; ! ok {
131
133
continue
132
134
}
133
- if invalidNode .optimistic == VALID {
135
+ if invalidNode .optimistic == valid {
134
136
f .store .nodesLock .Unlock ()
135
137
return invalidRoots , errInvalidOptimisticStatus
136
138
}
@@ -140,7 +142,7 @@ func (f *ForkChoice) SetOptimisticToInvalid(ctx context.Context, root, payload [
140
142
if ! previouslyBoosted && invalidNode .root == previousBoostRoot {
141
143
previouslyBoosted = true
142
144
}
143
- invalidNode .optimistic = INVALID
145
+ invalidNode .optimistic = invalid
144
146
invalidIndices [index ] = true
145
147
invalidNode .weight = 0
146
148
delete (f .store .nodesIndices , invalidNode .root )
0 commit comments