Skip to content

Commit

Permalink
Check sooner if it's block zero
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Nov 8, 2023
1 parent 8bb4325 commit 372c456
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions multiepoch-getBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,26 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex
}
tim.time("get entries")

if slot == 0 {
// NOTE: we assume this is on mainnet.
blockZeroBlocktime := uint64(1584368940)
zeroBlockHeight := uint64(0)
blockZeroBlockHash := lastEntryHash.String()
var blockResp GetBlockResponse
blockResp.Transactions = make([]GetTransactionResponse, 0)
blockResp.BlockTime = &blockZeroBlocktime
blockResp.Blockhash = lastEntryHash.String()
blockResp.ParentSlot = uint64(0)
blockResp.Rewards = make([]any, 0)
blockResp.BlockHeight = &zeroBlockHeight
blockResp.PreviousBlockhash = &blockZeroBlockHash // NOTE: this is what solana RPC does. Should it be nil instead? Or should it be the genesis hash?
return nil, conn.ReplyRaw(
ctx,
req.ID,
blockResp,
)
}

var allTransactions []GetTransactionResponse
var rewards any
hasRewards := !block.Rewards.(cidlink.Link).Cid.Equals(DummyCID)
Expand Down Expand Up @@ -391,6 +411,7 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex
allTransactions = append(allTransactions, txResp)
}
}

sort.Slice(allTransactions, func(i, j int) bool {
return allTransactions[i].Position < allTransactions[j].Position
})
Expand All @@ -401,25 +422,6 @@ func (multi *MultiEpoch) handleGetBlock(ctx context.Context, conn *requestContex
blockResp.Blockhash = lastEntryHash.String()
blockResp.ParentSlot = uint64(block.Meta.Parent_slot)
blockResp.Rewards = rewards
if slot == 0 {
// NOTE: we assume this is on mainnet.
blockZeroBlocktime := uint64(1584368940)
zeroBlockHeight := uint64(0)
blockZeroBlockHash := lastEntryHash.String()
var blockResp GetBlockResponse
blockResp.Transactions = make([]GetTransactionResponse, 0)
blockResp.BlockTime = &blockZeroBlocktime
blockResp.Blockhash = lastEntryHash.String()
blockResp.ParentSlot = uint64(0)
blockResp.Rewards = make([]any, 0)
blockResp.BlockHeight = &zeroBlockHeight
blockResp.PreviousBlockhash = &blockZeroBlockHash // NOTE: this is what solana RPC does. Should it be nil instead? Or should it be the genesis hash?
return nil, conn.ReplyRaw(
ctx,
req.ID,
blockResp,
)
}

{
blockHeight, ok := block.GetBlockHeight()
Expand Down

0 comments on commit 372c456

Please sign in to comment.