Skip to content

Commit

Permalink
bugfix: Missing DownloadSubBlocks path on the region block manifest o…
Browse files Browse the repository at this point in the history
…n a Prime Block
  • Loading branch information
gameofpointers committed Sep 29, 2023
1 parent 8636853 commit e66e41a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
13 changes: 11 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (c *Core) InsertChain(blocks types.Blocks) (int, error) {
if err.Error() == ErrSubNotSyncedToDom.Error() ||
err.Error() == ErrPendingEtxNotFound.Error() {
if nodeCtx != common.ZONE_CTX && c.sl.subClients[block.Location().SubIndex()] != nil {
c.sl.subClients[block.Location().SubIndex()].DownloadBlocksInManifest(context.Background(), block.SubManifest(), block.ParentEntropy())
c.sl.subClients[block.Location().SubIndex()].DownloadBlocksInManifest(context.Background(), block.Hash(), block.SubManifest(), block.ParentEntropy())
}
}
return idx, ErrPendingBlock
Expand Down Expand Up @@ -492,7 +492,7 @@ func (c *Core) Append(header *types.Header, manifest types.BlockManifest, domPen
return newPendingEtxs, subReorg, setHead, err
}

func (c *Core) DownloadBlocksInManifest(manifest types.BlockManifest, entropy *big.Int) {
func (c *Core) DownloadBlocksInManifest(blockHash common.Hash, manifest types.BlockManifest, entropy *big.Int) {
// Fetch the blocks for each hash in the manifest
for _, m := range manifest {
block := c.GetBlockOrCandidateByHash(m)
Expand All @@ -502,6 +502,15 @@ func (c *Core) DownloadBlocksInManifest(manifest types.BlockManifest, entropy *b
c.addToQueueIfNotAppended(block)
}
}
if common.NodeLocation.Context() == common.REGION_CTX {
block := c.GetBlockOrCandidateByHash(blockHash)
if block != nil {
// If a prime block comes in
if c.sl.subClients[block.Location().SubIndex()] != nil {
c.sl.subClients[block.Location().SubIndex()].DownloadBlocksInManifest(context.Background(), block.Hash(), block.SubManifest(), block.ParentEntropy())
}
}
}
}

// ConstructLocalBlock takes a header and construct the Block locally
Expand Down
4 changes: 2 additions & 2 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ func (b *QuaiAPIBackend) Append(header *types.Header, manifest types.BlockManife
return b.eth.core.Append(header, manifest, domPendingHeader, domTerminus, domOrigin, newInboundEtxs)
}

func (b *QuaiAPIBackend) DownloadBlocksInManifest(manifest types.BlockManifest, entropy *big.Int) {
b.eth.core.DownloadBlocksInManifest(manifest, entropy)
func (b *QuaiAPIBackend) DownloadBlocksInManifest(hash common.Hash, manifest types.BlockManifest, entropy *big.Int) {
b.eth.core.DownloadBlocksInManifest(hash, manifest, entropy)
}

func (b *QuaiAPIBackend) ConstructLocalMinedBlock(header *types.Header) (*types.Block, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/quaiapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Backend interface {
SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription
WriteBlock(block *types.Block)
Append(header *types.Header, manifest types.BlockManifest, domPendingHeader *types.Header, domTerminus common.Hash, domOrigin bool, newInboundEtxs types.Transactions) (types.Transactions, bool, bool, error)
DownloadBlocksInManifest(manifest types.BlockManifest, entropy *big.Int)
DownloadBlocksInManifest(hash common.Hash, manifest types.BlockManifest, entropy *big.Int)
ConstructLocalMinedBlock(header *types.Header) (*types.Block, error)
InsertBlock(ctx context.Context, block *types.Block) (int, error)
PendingBlock() *types.Block
Expand Down
3 changes: 2 additions & 1 deletion internal/quaiapi/quai_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ func (s *PublicBlockChainQuaiAPI) Append(ctx context.Context, raw json.RawMessag
}

type DownloadBlocksInManifestArgs struct {
Hash common.Hash `json:"hash"`
Manifest types.BlockManifest `json:"manifest"`
Entropy *big.Int `json:"entropy"`
}
Expand All @@ -658,7 +659,7 @@ func (s *PublicBlockChainQuaiAPI) DownloadBlocksInManifest(ctx context.Context,
if err := json.Unmarshal(raw, &manifest); err != nil {
return
}
s.b.DownloadBlocksInManifest(manifest.Manifest, manifest.Entropy)
s.b.DownloadBlocksInManifest(manifest.Hash, manifest.Manifest, manifest.Entropy)
}

type SubRelay struct {
Expand Down
3 changes: 2 additions & 1 deletion quaiclient/quaiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ func (ec *Client) Append(ctx context.Context, header *types.Header, manifest typ
return aReturns.Etxs, aReturns.SubReorg, aReturns.SetHead, nil
}

func (ec *Client) DownloadBlocksInManifest(ctx context.Context, manifest types.BlockManifest, entropy *big.Int) {
func (ec *Client) DownloadBlocksInManifest(ctx context.Context, hash common.Hash, manifest types.BlockManifest, entropy *big.Int) {
fields := map[string]interface{}{
"hash": hash,
"manifest": manifest,
"entropy": entropy,
}
Expand Down

0 comments on commit e66e41a

Please sign in to comment.