Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit 57a39ef

Browse files
committed
update blob tx
1 parent e7ac54b commit 57a39ef

File tree

4 files changed

+149
-20
lines changed

4 files changed

+149
-20
lines changed

cmd/flags/proposer.go

+6
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ var (
122122
Value: false,
123123
Category: proposerCategory,
124124
}
125+
BlobAllowed = &cli.BoolFlag{
126+
Name: "blobAllowed",
127+
Usage: "Send blob tx when propose block",
128+
Value: false,
129+
Category: proposerCategory,
130+
}
125131
)
126132

127133
// ProposerFlags All proposer flags.

proposer/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Config struct {
3939
TierFeePriceBump *big.Int
4040
MaxTierFeePriceBumps uint64
4141
IncludeParentMetaHash bool
42+
BlobAllowed bool
4243
}
4344

4445
// NewConfigFromCliContext initializes a Config instance from
@@ -126,5 +127,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) {
126127
TierFeePriceBump: new(big.Int).SetUint64(c.Uint64(flags.TierFeePriceBump.Name)),
127128
MaxTierFeePriceBumps: c.Uint64(flags.MaxTierFeePriceBumps.Name),
128129
IncludeParentMetaHash: c.Bool(flags.ProposeBlockIncludeParentMetaHash.Name),
130+
BlobAllowed: c.Bool(flags.BlobAllowed.Name),
129131
}, nil
130132
}

proposer/proposer.go

+116-8
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,14 @@ func (p *Proposer) sendTxListByBlobTx(ctx context.Context, txListBytes []byte) (
324324
return tx, nil
325325
}
326326

327-
// sendProposeBlockTx tries to send a TaikoL1.proposeBlock transaction.
328-
func (p *Proposer) sendProposeBlockTx(
327+
func (p *Proposer) sendProposeBlockTxWithBlobHash(
329328
ctx context.Context,
330329
blobHash common.Hash,
331330
nonce *uint64,
332331
assignment *encoding.ProverAssignment,
333332
assignedProver common.Address,
334333
maxFee *big.Int,
335-
isReplacement bool,
336-
) (*types.Transaction, error) {
334+
isReplacement bool) (*types.Transaction, error) {
337335
// Propose the transactions list
338336
opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1ChainID, maxFee)
339337
if err != nil {
@@ -415,6 +413,96 @@ func (p *Proposer) sendProposeBlockTx(
415413
return proposeTx, nil
416414
}
417415

416+
// sendProposeBlockTx tries to send a TaikoL1.proposeBlock transaction.
417+
func (p *Proposer) sendProposeBlockTx(
418+
ctx context.Context,
419+
txListBytes []byte,
420+
nonce *uint64,
421+
assignment *encoding.ProverAssignment,
422+
assignedProver common.Address,
423+
maxFee *big.Int,
424+
isReplacement bool,
425+
) (*types.Transaction, error) {
426+
// Propose the transactions list
427+
opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1ChainID, maxFee)
428+
if err != nil {
429+
return nil, err
430+
}
431+
if nonce != nil {
432+
opts.Nonce = new(big.Int).SetUint64(*nonce)
433+
}
434+
opts.GasLimit = p.ProposeBlockTxGasLimit
435+
if isReplacement {
436+
if opts, err = rpc.IncreaseGasTipCap(
437+
ctx,
438+
p.rpc,
439+
opts,
440+
p.proposerAddress,
441+
new(big.Int).SetUint64(p.ProposeBlockTxReplacementMultiplier),
442+
p.ProposeBlockTxGasTipCap,
443+
); err != nil {
444+
return nil, err
445+
}
446+
}
447+
448+
var parentMetaHash = [32]byte{}
449+
if p.IncludeParentMetaHash {
450+
state, err := p.rpc.TaikoL1.State(&bind.CallOpts{Context: ctx})
451+
if err != nil {
452+
return nil, err
453+
}
454+
455+
parent, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, state.SlotB.NumBlocks-1)
456+
if err != nil {
457+
return nil, err
458+
}
459+
460+
parentMetaHash = parent.MetaHash
461+
}
462+
463+
hookCalls := make([]encoding.HookCall, 0)
464+
465+
// initially just use the AssignmentHook default.
466+
// TODO: flag for additional hook addresses and data.
467+
hookInputData, err := encoding.EncodeAssignmentHookInput(&encoding.AssignmentHookInput{
468+
Assignment: assignment,
469+
Tip: common.Big0, // TODO: flag for tip
470+
})
471+
if err != nil {
472+
return nil, err
473+
}
474+
475+
hookCalls = append(hookCalls, encoding.HookCall{
476+
Hook: p.AssignmentHookAddress,
477+
Data: hookInputData,
478+
})
479+
480+
encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{
481+
AssignedProver: assignedProver,
482+
ExtraData: rpc.StringToBytes32(p.ExtraData),
483+
TxListByteOffset: common.Big0,
484+
TxListByteSize: common.Big0,
485+
BlobHash: [32]byte{},
486+
CacheBlobForReuse: false,
487+
ParentMetaHash: parentMetaHash,
488+
HookCalls: hookCalls,
489+
})
490+
if err != nil {
491+
return nil, err
492+
}
493+
494+
proposeTx, err := p.rpc.TaikoL1.ProposeBlock(
495+
opts,
496+
encodedParams,
497+
txListBytes,
498+
)
499+
if err != nil {
500+
return nil, encoding.TryParsingCustomError(err)
501+
}
502+
503+
return proposeTx, nil
504+
}
505+
418506
// ProposeTxList proposes the given transactions list to TaikoL1 smart contract.
419507
func (p *Proposer) ProposeTxList(
420508
ctx context.Context,
@@ -433,7 +521,6 @@ func (p *Proposer) ProposeTxList(
433521

434522
var (
435523
isReplacement bool
436-
blobTx *types.Transaction
437524
tx *types.Transaction
438525
)
439526
if err := backoff.Retry(
@@ -443,16 +530,37 @@ func (p *Proposer) ProposeTxList(
443530
}
444531

445532
// Send tx list by blob tx.
446-
if blobTx == nil {
447-
blobTx, err = p.sendTxListByBlobTx(ctx, txListBytes)
533+
if p.BlobAllowed {
534+
blobTx, err := p.sendTxListByBlobTx(ctx, txListBytes)
448535
if err != nil {
449536
return nil
450537
}
538+
if tx, err = p.sendProposeBlockTxWithBlobHash(
539+
ctx,
540+
blobTx.BlobHashes()[0],
541+
nonce,
542+
assignment,
543+
proverAddress,
544+
maxFee,
545+
isReplacement,
546+
); err != nil {
547+
log.Warn("Failed to send taikoL1.proposeBlock blob transaction", "error", encoding.TryParsingCustomError(err))
548+
if strings.Contains(err.Error(), core.ErrNonceTooLow.Error()) {
549+
return nil
550+
}
551+
if strings.Contains(err.Error(), txpool.ErrReplaceUnderpriced.Error()) {
552+
isReplacement = true
553+
} else {
554+
isReplacement = false
555+
}
556+
return err
557+
}
558+
return nil
451559
}
452560

453561
if tx, err = p.sendProposeBlockTx(
454562
ctx,
455-
blobTx.BlobHashes()[0],
563+
txListBytes,
456564
nonce,
457565
assignment,
458566
proverAddress,

proposer/proposer_test.go

+25-12
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,32 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() {
192192
)
193193
s.Nil(err)
194194

195-
// Send blob tx.
196-
blobTx, err := s.p.sendTxListByBlobTx(context.Background(), encoded)
197-
s.Nil(err)
198-
199-
newTx, err := s.p.sendProposeBlockTx(
200-
context.Background(),
201-
blobTx.BlobHashes()[0],
202-
&nonce,
203-
signedAssignment,
204-
proverAddress,
205-
fee,
206-
true,
195+
var (
196+
ctx = context.Background()
197+
newTx *types.Transaction
207198
)
199+
if s.p.BlobAllowed {
200+
blobTx, blobErr := s.p.sendTxListByBlobTx(ctx, encoded)
201+
s.Nil(blobErr)
202+
newTx, err = s.p.sendProposeBlockTxWithBlobHash(
203+
ctx,
204+
blobTx.BlobHashes()[0],
205+
&nonce,
206+
signedAssignment,
207+
proverAddress,
208+
fee,
209+
true)
210+
} else {
211+
newTx, err = s.p.sendProposeBlockTx(
212+
context.Background(),
213+
encoded,
214+
&nonce,
215+
signedAssignment,
216+
proverAddress,
217+
fee,
218+
true,
219+
)
220+
}
208221
s.Nil(err)
209222
s.Greater(newTx.GasTipCap().Uint64(), tx.GasTipCap().Uint64())
210223
}

0 commit comments

Comments
 (0)