Skip to content

Commit bbdcd6f

Browse files
authored
fix(dot/state, lib/grandpa): update justification and SignedVote handling in database (ChainSafe#1682)
1 parent 48405e7 commit bbdcd6f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+669
-525
lines changed

dot/core/interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ type BlockState interface {
3838
GetBlockByHash(common.Hash) (*types.Block, error)
3939
GenesisHash() common.Hash
4040
GetSlotForBlock(common.Hash) (uint64, error)
41-
GetFinalizedHeader(uint64, uint64) (*types.Header, error)
42-
GetFinalizedHash(uint64, uint64) (common.Hash, error)
43-
SetFinalizedHash(common.Hash, uint64, uint64) error
41+
GetFinalisedHeader(uint64, uint64) (*types.Header, error)
42+
GetFinalisedHash(uint64, uint64) (common.Hash, error)
43+
SetFinalisedHash(common.Hash, uint64, uint64) error
4444
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
4545
UnregisterImportedChannel(id byte)
4646
RegisterFinalizedChannel(ch chan<- *types.FinalisationInfo) (byte, error)

dot/digest/digest_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ func TestHandler_GrandpaScheduledChange(t *testing.T) {
139139

140140
headers := addTestBlocksToState(t, 2, handler.blockState)
141141
for i, h := range headers {
142-
handler.blockState.(*state.BlockState).SetFinalizedHash(h.Hash(), uint64(i), 0)
142+
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
143143
}
144144

145145
// authorities should change on start of block 3 from start
146146
headers = addTestBlocksToState(t, 1, handler.blockState)
147147
for _, h := range headers {
148-
handler.blockState.(*state.BlockState).SetFinalizedHash(h.Hash(), 3, 0)
148+
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), 3, 0)
149149
}
150150

151151
time.Sleep(time.Millisecond * 500)
@@ -232,7 +232,7 @@ func TestHandler_GrandpaPauseAndResume(t *testing.T) {
232232

233233
headers := addTestBlocksToState(t, 3, handler.blockState)
234234
for i, h := range headers {
235-
handler.blockState.(*state.BlockState).SetFinalizedHash(h.Hash(), uint64(i), 0)
235+
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
236236
}
237237

238238
time.Sleep(time.Millisecond * 100)

dot/network/mock_block_state.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dot/network/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ func (s *Service) sentBlockIntervalTelemetry() {
337337
}
338338
bestHash := best.Hash()
339339

340-
finalized, err := s.blockState.GetFinalizedHeader(0, 0) //nolint
340+
finalized, err := s.blockState.GetFinalisedHeader(0, 0) //nolint
341341
if err != nil {
342342
continue
343343
}

dot/network/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type BlockState interface {
2929
BestBlockNumber() (*big.Int, error)
3030
GenesisHash() common.Hash
3131
HasBlockBody(common.Hash) (bool, error)
32-
GetFinalizedHeader(round, setID uint64) (*types.Header, error)
32+
GetFinalisedHeader(round, setID uint64) (*types.Header, error)
3333
GetHashByNumber(num *big.Int) (common.Hash, error)
3434
}
3535

dot/network/sync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ func (q *syncQueue) benchmark() {
339339
}
340340

341341
if before.Number.Int64() >= q.goal {
342-
finalised, err := q.s.blockState.GetFinalizedHeader(0, 0) //nolint
342+
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0) //nolint
343343
if err != nil {
344344
continue
345345
}
@@ -742,7 +742,7 @@ func (q *syncQueue) handleBlockJustification(data []*types.BlockData) {
742742
}
743743

744744
func (q *syncQueue) handleBlockData(data []*types.BlockData) {
745-
finalised, err := q.s.blockState.GetFinalizedHeader(0, 0)
745+
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0)
746746
if err != nil {
747747
panic(err) // this should never happen
748748
}
@@ -790,7 +790,7 @@ func (q *syncQueue) handleBlockDataFailure(idx int, err error, data []*types.Blo
790790
logger.Warn("failed to handle block data", "failed on block", q.currStart+int64(idx), "error", err)
791791

792792
if errors.Is(err, chaindb.ErrKeyNotFound) || errors.Is(err, blocktree.ErrParentNotFound) {
793-
finalised, err := q.s.blockState.GetFinalizedHeader(0, 0)
793+
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0)
794794
if err != nil {
795795
panic(err)
796796
}

dot/network/test_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func NewMockBlockState(n *big.Int) *MockBlockState {
3737
m.On("GenesisHash").Return(common.NewHash([]byte{}))
3838
m.On("BestBlockNumber").Return(big.NewInt(1), nil)
3939
m.On("HasBlockBody", mock.AnythingOfType("common.Hash")).Return(false, nil)
40-
m.On("GetFinalizedHeader", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(header, nil)
40+
m.On("GetFinalisedHeader", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(header, nil)
4141
m.On("GetHashByNumber", mock.AnythingOfType("*big.Int")).Return(common.Hash{}, nil)
4242

4343
return m

dot/rpc/modules/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type BlockAPI interface {
3030
BestBlockHash() common.Hash
3131
GetBlockByHash(hash common.Hash) (*types.Block, error)
3232
GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
33-
GetFinalizedHash(uint64, uint64) (common.Hash, error)
33+
GetFinalisedHash(uint64, uint64) (common.Hash, error)
3434
HasJustification(hash common.Hash) (bool, error)
3535
GetJustification(hash common.Hash) ([]byte, error)
3636
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)

dot/rpc/modules/api_mocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewMockBlockAPI() *modulesmocks.MockBlockAPI {
2626
m.On("BestBlockHash").Return(common.Hash{})
2727
m.On("GetBlockByHash", mock.AnythingOfType("common.Hash")).Return(nil, nil)
2828
m.On("GetBlockHash", mock.AnythingOfType("*big.Int")).Return(nil, nil)
29-
m.On("GetFinalizedHash", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(common.Hash{}, nil)
29+
m.On("GetFinalisedHash", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(common.Hash{}, nil)
3030
m.On("RegisterImportedChannel", mock.AnythingOfType("chan<- *types.Block")).Return(byte(0), nil)
3131
m.On("UnregisterImportedChannel", mock.AnythingOfType("uint8"))
3232
m.On("RegisterFinalizedChannel", mock.AnythingOfType("chan<- *types.FinalisationInfo")).Return(byte(0), nil)

dot/rpc/modules/chain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (cm *ChainModule) GetHead(r *http.Request, req *ChainBlockNumberRequest, re
135135

136136
// GetFinalizedHead returns the most recently finalised block hash
137137
func (cm *ChainModule) GetFinalizedHead(r *http.Request, req *EmptyRequest, res *ChainHashResponse) error {
138-
h, err := cm.blockAPI.GetFinalizedHash(0, 0)
138+
h, err := cm.blockAPI.GetFinalisedHash(0, 0)
139139
if err != nil {
140140
return err
141141
}
@@ -146,7 +146,7 @@ func (cm *ChainModule) GetFinalizedHead(r *http.Request, req *EmptyRequest, res
146146

147147
// GetFinalizedHeadByRound returns the hash of the block finalised at the given round and setID
148148
func (cm *ChainModule) GetFinalizedHeadByRound(r *http.Request, req *ChainFinalizedHeadRequest, res *ChainHashResponse) error {
149-
h, err := cm.blockAPI.GetFinalizedHash(req.Round, req.SetID)
149+
h, err := cm.blockAPI.GetFinalisedHash(req.Round, req.SetID)
150150
if err != nil {
151151
return err
152152
}

0 commit comments

Comments
 (0)