Skip to content

Commit

Permalink
bugfix: UpdateDom no longer calculates, uses the pendingHeader given by
Browse files Browse the repository at this point in the history
the zone

UpdateDom takes zone pending header as input rather than entropy
  • Loading branch information
kiltsonfire authored and gameofpointers committed Sep 12, 2023
1 parent ae4e089 commit ade2813
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 37 deletions.
4 changes: 2 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ func (c *Core) SubRelayPendingHeader(slPendingHeader types.PendingHeader, newEnt
c.sl.SubRelayPendingHeader(slPendingHeader, newEntropy, location, subReorg)
}

func (c *Core) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, newEntropy *big.Int, location common.Location) {
c.sl.UpdateDom(oldTerminus, newTerminus, newEntropy, location)
func (c *Core) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, pendingHeader *types.Header, location common.Location) {
c.sl.UpdateDom(oldTerminus, newTerminus, pendingHeader, location)
}

func (c *Core) NewGenesisPendigHeader(pendingHeader *types.Header) {
Expand Down
48 changes: 20 additions & 28 deletions core/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (sl *Slice) Append(header *types.Header, domPendingHeader *types.Header, do
if updateDom {
log.Info("Append updateDom", "oldTermini():", bestPh.Termini().DomTerminus(), "newTermini():", pendingHeaderWithTermini.Termini().DomTerminus(), "location:", common.NodeLocation)
if sl.domClient != nil {
go sl.domClient.UpdateDom(context.Background(), bestPh.Termini().DomTerminus(), pendingHeaderWithTermini.Termini().DomTerminus(), pendingHeaderWithTermini.Header().ParentEntropy(), common.NodeLocation)
go sl.domClient.UpdateDom(context.Background(), bestPh.Termini().DomTerminus(), pendingHeaderWithTermini.Termini().DomTerminus(), pendingHeaderWithTermini.Header(), common.NodeLocation)
}
}
return block.ExtTransactions(), subReorg, nil
Expand Down Expand Up @@ -377,7 +377,7 @@ func (sl *Slice) relayPh(block *types.Block, pendingHeaderWithTermini types.Pend

// If a zone changes its best ph key on a dom block, it sends a signal to the
// dom and we can relay that information to the coords, to build on the right dom header
func (sl *Slice) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, newEntropy *big.Int, location common.Location) {
func (sl *Slice) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, pendingHeader *types.Header, location common.Location) {
nodeCtx := common.NodeLocation.Context()
sl.phCacheMu.Lock()
defer sl.phCacheMu.Unlock()
Expand All @@ -391,40 +391,28 @@ func (sl *Slice) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, new
log.Info("UpdateDom:", "oldTerminus:", oldTerminus, "newTerminus:", newTerminus, "oldDomTerminus:", oldDomTermini.DomTerminus(), "newDomTerminus:", newDomTermini.DomTerminus())
if nodeCtx == common.REGION_CTX && oldDomTermini.DomTerminus() == newDomTermini.DomTerminus() {
// Can update
block := sl.hc.GetBlockByHash(newTerminus)
newPh := types.NewPendingHeader(pendingHeader, *newDomTermini)
sl.bestPhKey = newTerminus
if block != nil {
pendingHeaderWithTermini, err := sl.generateSlicePendingHeader(block, *newDomTermini, types.EmptyHeader(), false, true, false)
if err != nil {
return
}
log.Info("pendingHeaderWithTermini:", "parent Hash:", pendingHeaderWithTermini.Header().ParentHash(), "Number", pendingHeaderWithTermini.Header().NumberArray())
for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, newEntropy, common.Location{}, true)
}
log.Info("newPh:", "parent Hash:", newPh.Header().ParentHash(), "Number", newPh.Header().NumberArray())
for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
sl.subClients[i].SubRelayPendingHeader(context.Background(), newPh, pendingHeader.ParentEntropy(common.ZONE_CTX), common.Location{}, true)
}
}
return
} else {
// need to update dom
log.Info("Append need to updateDom", "oldDomTermini:", oldDomTermini, "newDomTermini:", newDomTermini, "location:", common.NodeLocation)
if sl.domClient != nil {
go sl.domClient.UpdateDom(context.Background(), oldDomTermini.DomTerminus(), newDomTermini.DomTerminus(), newEntropy, location)
go sl.domClient.UpdateDom(context.Background(), oldDomTermini.DomTerminus(), newDomTermini.DomTerminus(), pendingHeader, location)
} else {
// Can update
block := sl.hc.GetBlockByHash(newTerminus)
newPh := types.NewPendingHeader(pendingHeader, *newDomTermini)
sl.bestPhKey = newTerminus
if block != nil {
pendingHeaderWithTermini, err := sl.generateSlicePendingHeader(block, *newDomTermini, types.EmptyHeader(), false, true, false)
if err != nil {
return
}
log.Info("pendingHeaderWithTermini:", "parent Hash:", pendingHeaderWithTermini.Header().ParentHash(), "Number", pendingHeaderWithTermini.Header().NumberArray())
for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
sl.subClients[i].SubRelayPendingHeader(context.Background(), pendingHeaderWithTermini, newEntropy, location, true)
}
log.Info("newPh:", "parent Hash:", newPh.Header().ParentHash(), "Number", newPh.Header().NumberArray())
for _, i := range sl.randomRelayArray() {
if sl.subClients[i] != nil {
sl.subClients[i].SubRelayPendingHeader(context.Background(), newPh, pendingHeader.ParentEntropy(common.ZONE_CTX), common.Location{}, true)
}
}
return
Expand Down Expand Up @@ -720,6 +708,10 @@ func (sl *Slice) computePendingHeader(localPendingHeaderWithTermini types.Pendin
var newPh *types.Header

if exists {
if domOrigin {
newPh = sl.combinePendingHeader(localPendingHeaderWithTermini.Header(), domPendingHeader, nodeCtx, true)
return types.NewPendingHeader(types.CopyHeader(newPh), localPendingHeaderWithTermini.Termini())
}
newPh = sl.combinePendingHeader(localPendingHeaderWithTermini.Header(), cachedPendingHeaderWithTermini.Header(), nodeCtx, true)
return types.NewPendingHeader(types.CopyHeader(newPh), localPendingHeaderWithTermini.Termini())
} else {
Expand Down Expand Up @@ -747,9 +739,9 @@ func (sl *Slice) updatePhCacheFromDom(pendingHeader types.PendingHeader, termini
bestPh, exists := sl.readPhCache(sl.bestPhKey)
nodeCtx := common.NodeLocation.Context()
if nodeCtx == common.ZONE_CTX && exists && sl.bestPhKey != localPendingHeader.Termini().DomTerminus() && !sl.poem(newEntropy, bestPh.Header().ParentEntropy()) {
log.Info("subrelay rejected", "local dom terminus", localPendingHeader.Termini().DomTerminus(), "Number", localPendingHeader.Header().NumberArray(), "best ph key", sl.bestPhKey, "number", bestPh.Header().NumberArray(), "newentropy", newEntropy)
log.Info("subrelay rejected", "local dom terminus", localPendingHeader.Termini().DomTerminus(), "Number", combinedPendingHeader.NumberArray(), "best ph key", sl.bestPhKey, "number", bestPh.Header().NumberArray(), "newentropy", newEntropy)
sl.updatePhCache(types.NewPendingHeader(combinedPendingHeader, localPendingHeader.Termini()), false, nil, sl.poem(newEntropy, localPendingHeader.Header().ParentEntropy()))
go sl.domClient.UpdateDom(context.Background(), localPendingHeader.Termini().DomTerminus(), sl.bestPhKey, bestPh.Header().ParentEntropy(), common.NodeLocation)
go sl.domClient.UpdateDom(context.Background(), localPendingHeader.Termini().DomTerminus(), sl.bestPhKey, bestPh.Header(), common.NodeLocation)
return nil
}
// Pick the head
Expand All @@ -762,7 +754,7 @@ func (sl *Slice) updatePhCacheFromDom(pendingHeader types.PendingHeader, termini
log.Error("Error setting current header", "err", err, "Hash", block.Hash())
return err
}
log.Info("Choosing phHeader pickPhHead:", "NumberArray:", localPendingHeader.Header().NumberArray(), "Number:", localPendingHeader.Header().Number(), "ParentHash:", localPendingHeader.Header().ParentHash(), "Terminus:", localPendingHeader.Termini().DomTerminus())
log.Info("Choosing phHeader pickPhHead:", "NumberArray:", combinedPendingHeader.NumberArray(), "Number:", combinedPendingHeader.Number(), "ParentHash:", combinedPendingHeader.ParentHash(), "Terminus:", localPendingHeader.Termini().DomTerminus())
sl.bestPhKey = localPendingHeader.Termini().DomTerminus()
if block.Hash() != sl.hc.CurrentHeader().Hash() {
sl.hc.chainHeadFeed.Send(ChainHeadEvent{block})
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ func (b *QuaiAPIBackend) SubRelayPendingHeader(pendingHeader types.PendingHeader
b.eth.core.SubRelayPendingHeader(pendingHeader, newEntropy, location, subReorg)
}

func (b *QuaiAPIBackend) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, newEntropy *big.Int, location common.Location) {
b.eth.core.UpdateDom(oldTerminus, newTerminus, newEntropy, location)
func (b *QuaiAPIBackend) UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, pendingHeader *types.Header, location common.Location) {
b.eth.core.UpdateDom(oldTerminus, newTerminus, pendingHeader, location)
}

func (b *QuaiAPIBackend) RequestDomToAppendOrFetch(hash common.Hash, order int) {
Expand Down
2 changes: 1 addition & 1 deletion internal/quaiapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Backend interface {
InsertBlock(ctx context.Context, block *types.Block) (int, error)
PendingBlock() *types.Block
SubRelayPendingHeader(pendingHeader types.PendingHeader, newEntropy *big.Int, location common.Location, subReorg bool)
UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, newEntropy *big.Int, location common.Location)
UpdateDom(oldTerminus common.Hash, newTerminus common.Hash, pendingHeader *types.Header, location common.Location)
RequestDomToAppendOrFetch(hash common.Hash, order int)
NewGenesisPendingHeader(pendingHeader *types.Header)
GetPendingHeader() (*types.Header, error)
Expand Down
4 changes: 2 additions & 2 deletions internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ type DomUpdate struct {
OldTerminus common.Hash
NewTerminus common.Hash
Location common.Location
NewEntropy *big.Int
Header *types.Header
}

func (s *PublicBlockChainQuaiAPI) UpdateDom(ctx context.Context, raw json.RawMessage) {
Expand All @@ -677,7 +677,7 @@ func (s *PublicBlockChainQuaiAPI) UpdateDom(ctx context.Context, raw json.RawMes
return
}

s.b.UpdateDom(domUpdate.OldTerminus, domUpdate.NewTerminus, domUpdate.NewEntropy, domUpdate.Location)
s.b.UpdateDom(domUpdate.OldTerminus, domUpdate.NewTerminus, domUpdate.Header, domUpdate.Location)
}

type RequestDomToAppendOrFetchArgs struct {
Expand Down
4 changes: 2 additions & 2 deletions quaiclient/quaiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ func (ec *Client) SubRelayPendingHeader(ctx context.Context, pendingHeader types
ec.c.CallContext(ctx, nil, "quai_subRelayPendingHeader", data)
}

func (ec *Client) UpdateDom(ctx context.Context, oldTerminus common.Hash, newTerminus common.Hash, newEntropy *big.Int, location common.Location) {
func (ec *Client) UpdateDom(ctx context.Context, oldTerminus common.Hash, newTerminus common.Hash, pendingHeader *types.Header, location common.Location) {
data := map[string]interface{}{"OldTerminus": oldTerminus}
data["NewTerminus"] = newTerminus
data["Location"] = location
data["NewEntropy"] = newEntropy
data["Header"] = pendingHeader.RPCMarshalHeader()

ec.c.CallContext(ctx, nil, "quai_updateDom", data)
}
Expand Down

0 comments on commit ade2813

Please sign in to comment.