Skip to content

Commit af5a0c3

Browse files
authored
Switch to using latest finalized block as transaction reference block (#874)
1 parent 1f4a295 commit af5a0c3

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

examples/examples.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ func RandomAccount(flowClient access.Client) (flow.Address, *flow.AccountKey, cr
140140
}
141141

142142
func GetReferenceBlockId(flowClient access.Client) flow.Identifier {
143-
block, err := flowClient.GetLatestBlock(context.Background(), true)
143+
// We use the latest finalized block as the reference block ID.
144+
// This is the block that has been finalized and is guaranteed to be included in the chain.
145+
// It is the best choice for a reference block ID, as block sealing lags behind finalization
146+
// and using a sealed block may cause the reference to fall outside the expiration window.
147+
block, err := flowClient.GetLatestBlock(context.Background(), false)
144148
Handle(err)
145149

146150
return block.ID

transaction.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ func (t *Transaction) Argument(i int, options ...jsoncdc.Option) (cadence.Value,
178178
//
179179
// For example, if a transaction references a block with height of X and the network limit is 10,
180180
// a block with height X+10 is the last block that is allowed to include this transaction.
181+
//
182+
// It is recommended to use the latest finalized block as the reference block ID.
183+
// Transaction expiry is determined by the height difference between the reference block
184+
// and the block that includes the transaction. Block sealing lags behind finalization and
185+
// using the latest sealed block may cause the reference to fall outside the expiration window.
181186
func (t *Transaction) SetReferenceBlockID(blockID Identifier) *Transaction {
182187
t.ReferenceBlockID = blockID
183188
return t

0 commit comments

Comments
 (0)