Skip to content

Commit

Permalink
Latest milestone response fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avalkov committed Jan 3, 2025
1 parent 7e465cb commit eba691c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
6 changes: 2 additions & 4 deletions consensus/bor/heimdall/milestone/milestone.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package milestone

import (
"math/big"

"github.com/ethereum/go-ethereum/common"
)

// milestone defines a response object type of bor milestone
type Milestone struct {
Proposer common.Address `json:"proposer"`
StartBlock *big.Int `json:"start_block"`
EndBlock *big.Int `json:"end_block"`
StartBlock uint64 `json:"start_block"`
EndBlock uint64 `json:"end_block"`
Hash common.Hash `json:"hash"`
BorChainID string `json:"bor_chain_id"`
MilestoneID string `json:"milestone_id"`
Expand Down
5 changes: 2 additions & 3 deletions consensus/bor/heimdallapp/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package heimdallapp
import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/bor/heimdall/milestone"
Expand Down Expand Up @@ -85,8 +84,8 @@ func (h *HeimdallAppClient) FetchLastNoAckMilestone(_ context.Context) (string,
func toBorMilestone(hdMilestone *milestoneTypes.Milestone) *milestone.Milestone {
return &milestone.Milestone{
Proposer: common.HexToAddress(hdMilestone.Proposer),
StartBlock: big.NewInt(int64(hdMilestone.StartBlock)),
EndBlock: big.NewInt(int64(hdMilestone.EndBlock)),
StartBlock: hdMilestone.StartBlock,
EndBlock: hdMilestone.EndBlock,
Hash: common.BytesToHash(hdMilestone.Hash),
BorChainID: hdMilestone.BorChainId,
Timestamp: hdMilestone.Timestamp,
Expand Down
5 changes: 2 additions & 3 deletions consensus/bor/heimdallgrpc/milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package heimdallgrpc
import (
"context"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/consensus/bor/heimdall"
"github.com/ethereum/go-ethereum/consensus/bor/heimdall/milestone"
Expand Down Expand Up @@ -37,8 +36,8 @@ func (h *HeimdallGRPCClient) FetchMilestone(ctx context.Context) (*milestone.Mil
log.Info("Fetched milestone")

milestone := &milestone.Milestone{
StartBlock: new(big.Int).SetUint64(res.Result.StartBlock),
EndBlock: new(big.Int).SetUint64(res.Result.EndBlock),
StartBlock: res.Result.StartBlock,
EndBlock: res.Result.EndBlock,
Hash: protoutils.ConvertH256ToHash(res.Result.RootHash),
Proposer: protoutils.ConvertH160toAddress(res.Result.Proposer),
BorChainID: res.Result.BorChainID,
Expand Down
8 changes: 4 additions & 4 deletions eth/handler_bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ func (h *ethHandler) fetchWhitelistMilestone(ctx context.Context, bor *bor.Bor,
return num, hash, err
}

num = milestone.EndBlock.Uint64()
num = milestone.EndBlock
hash = milestone.Hash

log.Debug("Got new milestone from heimdall", "start", milestone.StartBlock.Uint64(), "end", milestone.EndBlock.Uint64(), "hash", milestone.Hash.String())
log.Debug("Got new milestone from heimdall", "start", milestone.StartBlock, "end", milestone.EndBlock, "hash", milestone.Hash.String())

// Verify if the milestone fetched can be added to the local whitelist entry or not. If verified,
// the hash of the end block of the milestone is returned else appropriate error is returned.
_, err = verifier.verify(ctx, eth, h, milestone.StartBlock.Uint64(), milestone.EndBlock.Uint64(), milestone.Hash.String()[2:], false)
_, err = verifier.verify(ctx, eth, h, milestone.StartBlock, milestone.EndBlock, milestone.Hash.String()[2:], false)
if err != nil {
if errors.Is(err, errChainOutOfSync) {
log.Info("Whitelisting milestone deferred", "err", err)
} else {
log.Warn("Failed to whitelist milestone", "err", err)
}
h.downloader.UnlockSprint(milestone.EndBlock.Uint64())
h.downloader.UnlockSprint(milestone.EndBlock)
}

return num, hash, err
Expand Down

0 comments on commit eba691c

Please sign in to comment.