Skip to content

Commit

Permalink
replace finalized->finalised
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Jul 9, 2021
1 parent 5cab5a0 commit f4a23c0
Show file tree
Hide file tree
Showing 33 changed files with 75 additions and 75 deletions.
6 changes: 3 additions & 3 deletions dot/core/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ type BlockState interface {
GetBlockByHash(common.Hash) (*types.Block, error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
GetFinalizedHeader(uint64, uint64) (*types.Header, error)
GetFinalizedHash(uint64, uint64) (common.Hash, error)
SetFinalizedHash(common.Hash, uint64, uint64) error
GetFinalisedHeader(uint64, uint64) (*types.Header, error)
GetFinalisedHash(uint64, uint64) (common.Hash, error)
SetFinalisedHash(common.Hash, uint64, uint64) error
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
UnregisterImportedChannel(id byte)
RegisterFinalizedChannel(ch chan<- *types.FinalisationInfo) (byte, error)
Expand Down
6 changes: 3 additions & 3 deletions dot/digest/digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ func TestHandler_GrandpaScheduledChange(t *testing.T) {

headers := addTestBlocksToState(t, 2, handler.blockState)
for i, h := range headers {
handler.blockState.(*state.BlockState).SetFinalizedHash(h.Hash(), uint64(i), 0)
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
}

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

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

headers := addTestBlocksToState(t, 3, handler.blockState)
for i, h := range headers {
handler.blockState.(*state.BlockState).SetFinalizedHash(h.Hash(), uint64(i), 0)
handler.blockState.(*state.BlockState).SetFinalisedHash(h.Hash(), uint64(i), 0)
}

time.Sleep(time.Millisecond * 100)
Expand Down
4 changes: 2 additions & 2 deletions dot/network/mock_block_state.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dot/network/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (s *Service) sentBlockIntervalTelemetry() {
}
bestHash := best.Hash()

finalized, err := s.blockState.GetFinalizedHeader(0, 0) //nolint
finalized, err := s.blockState.GetFinalisedHeader(0, 0) //nolint
if err != nil {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion dot/network/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type BlockState interface {
BestBlockNumber() (*big.Int, error)
GenesisHash() common.Hash
HasBlockBody(common.Hash) (bool, error)
GetFinalizedHeader(round, setID uint64) (*types.Header, error)
GetFinalisedHeader(round, setID uint64) (*types.Header, error)
GetHashByNumber(num *big.Int) (common.Hash, error)
}

Expand Down
6 changes: 3 additions & 3 deletions dot/network/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (q *syncQueue) benchmark() {
}

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

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

if errors.Is(err, chaindb.ErrKeyNotFound) || errors.Is(err, blocktree.ErrParentNotFound) {
finalised, err := q.s.blockState.GetFinalizedHeader(0, 0)
finalised, err := q.s.blockState.GetFinalisedHeader(0, 0)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion dot/network/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewMockBlockState(n *big.Int) *MockBlockState {
m.On("GenesisHash").Return(common.NewHash([]byte{}))
m.On("BestBlockNumber").Return(big.NewInt(1), nil)
m.On("HasBlockBody", mock.AnythingOfType("common.Hash")).Return(false, nil)
m.On("GetFinalizedHeader", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(header, nil)
m.On("GetFinalisedHeader", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(header, nil)
m.On("GetHashByNumber", mock.AnythingOfType("*big.Int")).Return(common.Hash{}, nil)

return m
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type BlockAPI interface {
BestBlockHash() common.Hash
GetBlockByHash(hash common.Hash) (*types.Block, error)
GetBlockHash(blockNumber *big.Int) (*common.Hash, error)
GetFinalizedHash(uint64, uint64) (common.Hash, error)
GetFinalisedHash(uint64, uint64) (common.Hash, error)
HasJustification(hash common.Hash) (bool, error)
GetJustification(hash common.Hash) ([]byte, error)
RegisterImportedChannel(ch chan<- *types.Block) (byte, error)
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/api_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewMockBlockAPI() *modulesmocks.MockBlockAPI {
m.On("BestBlockHash").Return(common.Hash{})
m.On("GetBlockByHash", mock.AnythingOfType("common.Hash")).Return(nil, nil)
m.On("GetBlockHash", mock.AnythingOfType("*big.Int")).Return(nil, nil)
m.On("GetFinalizedHash", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(common.Hash{}, nil)
m.On("GetFinalisedHash", mock.AnythingOfType("uint64"), mock.AnythingOfType("uint64")).Return(common.Hash{}, nil)
m.On("RegisterImportedChannel", mock.AnythingOfType("chan<- *types.Block")).Return(byte(0), nil)
m.On("UnregisterImportedChannel", mock.AnythingOfType("uint8"))
m.On("RegisterFinalizedChannel", mock.AnythingOfType("chan<- *types.FinalisationInfo")).Return(byte(0), nil)
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (cm *ChainModule) GetHead(r *http.Request, req *ChainBlockNumberRequest, re

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

// GetFinalizedHeadByRound returns the hash of the block finalised at the given round and setID
func (cm *ChainModule) GetFinalizedHeadByRound(r *http.Request, req *ChainFinalizedHeadRequest, res *ChainHashResponse) error {
h, err := cm.blockAPI.GetFinalizedHash(req.Round, req.SetID)
h, err := cm.blockAPI.GetFinalisedHash(req.Round, req.SetID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dot/rpc/modules/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestChainGetFinalizedHeadByRound(t *testing.T) {
require.NoError(t, err)

testhash := header.Hash()
err = state.Block.SetFinalizedHash(testhash, 77, 1)
err = state.Block.SetFinalisedHash(testhash, 77, 1)
require.NoError(t, err)

req = ChainFinalizedHeadRequest{77, 1}
Expand Down
4 changes: 2 additions & 2 deletions dot/rpc/modules/mocks/block_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func NewBlockState(db chaindb.Database, bt *blocktree.BlockTree) (*BlockState, e
}

bs.genesisHash = genesisBlock.Header.Hash()
bs.lastFinalised, err = bs.GetFinalizedHash(0, 0)
bs.lastFinalised, err = bs.GetFinalisedHash(0, 0)
if err != nil {
return nil, fmt.Errorf("failed to get last finalised hash: %w", err)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func NewBlockStateFromGenesis(db chaindb.Database, header *types.Header) (*Block
bs.genesisHash = header.Hash()

// set the latest finalised head to the genesis header
err = bs.SetFinalizedHash(bs.genesisHash, 0, 0)
err = bs.SetFinalisedHash(bs.genesisHash, 0, 0)
if err != nil {
return nil, err
}
Expand Down
30 changes: 15 additions & 15 deletions dot/state/block_finalisation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ import (
"github.com/ChainSafe/gossamer/lib/common"
)

// finalizedHashKey = FinalizedBlockHashKey + round + setID (LE encoded)
func finalizedHashKey(round, setID uint64) []byte {
// finalisedHashKey = FinalizedBlockHashKey + round + setID (LE encoded)
func finalisedHashKey(round, setID uint64) []byte {
return append(common.FinalizedBlockHashKey, roundSetIDKey(round, setID)...)
}

// HasFinalizedBlock returns true if there is a finalised block for a given round and setID, false otherwise
func (bs *BlockState) HasFinalizedBlock(round, setID uint64) (bool, error) {
return bs.db.Has(finalizedHashKey(round, setID))
// HasFinalisedBlock returns true if there is a finalised block for a given round and setID, false otherwise
func (bs *BlockState) HasFinalisedBlock(round, setID uint64) (bool, error) {
return bs.db.Has(finalisedHashKey(round, setID))
}

// NumberIsFinalised checks if a block number is finalised or not
func (bs *BlockState) NumberIsFinalised(num *big.Int) (bool, error) {
header, err := bs.GetFinalizedHeader(0, 0)
header, err := bs.GetFinalisedHeader(0, 0)
if err != nil {
return false, err
}

return num.Cmp(header.Number) <= 0, nil
}

// GetFinalizedHeader returns the finalised block header by round and setID
func (bs *BlockState) GetFinalizedHeader(round, setID uint64) (*types.Header, error) {
h, err := bs.GetFinalizedHash(round, setID)
// GetFinalisedHeader returns the finalised block header by round and setID
func (bs *BlockState) GetFinalisedHeader(round, setID uint64) (*types.Header, error) {
h, err := bs.GetFinalisedHash(round, setID)
if err != nil {
return nil, err
}
Expand All @@ -59,19 +59,19 @@ func (bs *BlockState) GetFinalizedHeader(round, setID uint64) (*types.Header, er
return header, nil
}

// GetFinalizedHash gets the finalised block header by round and setID
func (bs *BlockState) GetFinalizedHash(round, setID uint64) (common.Hash, error) {
h, err := bs.db.Get(finalizedHashKey(round, setID))
// GetFinalisedHash gets the finalised block header by round and setID
func (bs *BlockState) GetFinalisedHash(round, setID uint64) (common.Hash, error) {
h, err := bs.db.Get(finalisedHashKey(round, setID))
if err != nil {
return common.Hash{}, err
}

return common.NewHash(h), nil
}

// SetFinalizedHash sets the latest finalised block header
// SetFinalisedHash sets the latest finalised block header
// Note that using round=0 and setID=0 would refer to the latest finalised hash
func (bs *BlockState) SetFinalizedHash(hash common.Hash, round, setID uint64) error {
func (bs *BlockState) SetFinalisedHash(hash common.Hash, round, setID uint64) error {
bs.Lock()
defer bs.Unlock()

Expand Down Expand Up @@ -110,7 +110,7 @@ func (bs *BlockState) SetFinalizedHash(hash common.Hash, round, setID uint64) er
}

bs.lastFinalised = hash
return bs.db.Put(finalizedHashKey(round, setID), hash[:])
return bs.db.Put(finalisedHashKey(round, setID), hash[:])
}

func (bs *BlockState) setFirstSlotOnFinalisation() error {
Expand Down
4 changes: 2 additions & 2 deletions dot/state/block_notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestFinalizedChannel(t *testing.T) {
chain, _ := AddBlocksToState(t, bs, 3)

for _, b := range chain {
bs.SetFinalizedHash(b.Hash(), 1, 0)
bs.SetFinalisedHash(b.Hash(), 1, 0)
}

for i := 0; i < 1; i++ {
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestFinalizedChannel_Multi(t *testing.T) {
}

time.Sleep(time.Millisecond * 10)
bs.SetFinalizedHash(chain[0].Hash(), 1, 0)
bs.SetFinalisedHash(chain[0].Hash(), 1, 0)
wg.Wait()

for _, id := range ids {
Expand Down
12 changes: 6 additions & 6 deletions dot/state/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func TestAddBlock_BlockNumberToHash(t *testing.T) {

func TestFinalizedHash(t *testing.T) {
bs := newTestBlockState(t, testGenesisHeader)
h, err := bs.GetFinalizedHash(0, 0)
h, err := bs.GetFinalisedHash(0, 0)
require.NoError(t, err)
require.Equal(t, testGenesisHeader.Hash(), h)

Expand All @@ -291,10 +291,10 @@ func TestFinalizedHash(t *testing.T) {
})
require.NoError(t, err)

err = bs.SetFinalizedHash(testhash, 1, 1)
err = bs.SetFinalisedHash(testhash, 1, 1)
require.NoError(t, err)

h, err = bs.GetFinalizedHash(1, 1)
h, err = bs.GetFinalisedHash(1, 1)
require.NoError(t, err)
require.Equal(t, testhash, h)
}
Expand All @@ -317,7 +317,7 @@ func TestFinalization_DeleteBlock(t *testing.T) {

// pick block to finalise
fin := leaves[len(leaves)-1]
err := bs.SetFinalizedHash(fin, 1, 1)
err := bs.SetFinalisedHash(fin, 1, 1)
require.NoError(t, err)

after := bs.bt.GetAllBlocks()
Expand Down Expand Up @@ -555,7 +555,7 @@ func TestNumberIsFinalised(t *testing.T) {

err = bs.SetHeader(header100)
require.NoError(t, err)
err = bs.SetFinalizedHash(header100.Hash(), 0, 0)
err = bs.SetFinalisedHash(header100.Hash(), 0, 0)
require.NoError(t, err)

fin, err = bs.NumberIsFinalised(big.NewInt(0))
Expand Down Expand Up @@ -598,7 +598,7 @@ func TestSetFinalisedHash_setFirstSlotOnFinalisation(t *testing.T) {

err = bs.SetHeader(header100)
require.NoError(t, err)
err = bs.SetFinalizedHash(header100.Hash(), 0, 0)
err = bs.SetFinalisedHash(header100.Hash(), 0, 0)
require.NoError(t, err)
require.Equal(t, header100.Hash(), bs.lastFinalised)

Expand Down
2 changes: 1 addition & 1 deletion dot/state/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (s *EpochState) GetEpochFromTime(t time.Time) (uint64, error) {
// SetFirstSlot sets the first slot number of the network
func (s *EpochState) SetFirstSlot(slot uint64) error {
// check if block 1 was finalised already; if it has, don't set first slot again
header, err := s.blockState.GetFinalizedHeader(0, 0)
header, err := s.blockState.GetFinalisedHeader(0, 0)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dot/state/offline_pruner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func NewOfflinePruner(inputDBPath, prunedDBPath string, bloomSize uint64, retain
// SetBloomFilter loads keys with storage prefix of last `retainBlockNum` blocks into the bloom filter
func (p *OfflinePruner) SetBloomFilter() error {
defer p.inputDB.Close() // nolint: errcheck
finalisedHash, err := p.blockState.GetFinalizedHash(0, 0)
finalisedHash, err := p.blockState.GetFinalisedHash(0, 0)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions dot/state/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *Service) Start() error {
if !bytes.Equal(btHead[:], bestHash[:]) {
logger.Info("detected abnormal node shutdown, restoring from last finalised block")

lastFinalised, err := s.Block.GetFinalizedHeader(0, 0) //nolint
lastFinalised, err := s.Block.GetFinalisedHeader(0, 0) //nolint
if err != nil {
return fmt.Errorf("failed to get latest finalised block: %w", err)
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *Service) Rewind(toBlock int64) error {
return err
}

err = s.Block.SetFinalizedHash(header.Hash(), 0, 0)
err = s.Block.SetFinalisedHash(header.Hash(), 0, 0)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dot/state/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func TestService_PruneStorage(t *testing.T) {
}

// finalise a block
serv.Block.SetFinalizedHash(toFinalize, 0, 0)
serv.Block.SetFinalisedHash(toFinalize, 0, 0)

time.Sleep(1 * time.Second)

Expand Down
2 changes: 1 addition & 1 deletion dot/sync/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type BlockState interface {
GetMessageQueue(common.Hash) ([]byte, error)
GetJustification(common.Hash) ([]byte, error)
SetJustification(hash common.Hash, data []byte) error
SetFinalizedHash(hash common.Hash, round, setID uint64) error
SetFinalisedHash(hash common.Hash, round, setID uint64) error
AddBlockToBlockTree(header *types.Header) error
GetHashByNumber(*big.Int) (common.Hash, error)
GetBlockByHash(common.Hash) (*types.Block, error)
Expand Down
2 changes: 1 addition & 1 deletion dot/sync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (s *Service) handleJustification(header *types.Header, justification []byte
return
}

err = s.blockState.SetFinalizedHash(header.Hash(), 0, 0)
err = s.blockState.SetFinalisedHash(header.Hash(), 0, 0)
if err != nil {
logger.Error("failed to set finalised hash", "error", err)
return
Expand Down
2 changes: 1 addition & 1 deletion lib/babe/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type BlockState interface {
GetArrivalTime(common.Hash) (time.Time, error)
GenesisHash() common.Hash
GetSlotForBlock(common.Hash) (uint64, error)
GetFinalizedHeader(uint64, uint64) (*types.Header, error)
GetFinalisedHeader(uint64, uint64) (*types.Header, error)
IsDescendantOf(parent, child common.Hash) (bool, error)
NumberIsFinalised(num *big.Int) (bool, error)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/grandpa/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
// ErrInvalidMessageType is returned when a network.Message cannot be decoded
ErrInvalidMessageType = errors.New("cannot decode invalid message type")

// ErrNotCommitMessage is returned when calling GetFinalizedHash on a message that isn't a CommitMessage
// ErrNotCommitMessage is returned when calling GetFinalisedHash on a message that isn't a CommitMessage
ErrNotCommitMessage = errors.New("cannot get finalised hash from VoteMessage")

// ErrNoJustification is returned when no justification can be found for a block, ie. it has not been finalised
Expand Down
Loading

0 comments on commit f4a23c0

Please sign in to comment.