-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e4e83a
commit d798b17
Showing
19 changed files
with
310 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package flags | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Required flags used by preconfirmations api. | ||
var ( | ||
PreconfAPIHTTPServerPort = &cli.Uint64Flag{ | ||
Name: "preconfapi.port", | ||
Usage: "Port to expose for http server", | ||
Category: preconfApiCategory, | ||
Value: 9871, | ||
EnvVars: []string{"PRECONFAPI_PORT"}, | ||
} | ||
) | ||
|
||
// PreconfAPIFlags contains all preconfirmations API flags. | ||
var PreconfAPIFlags = []cli.Flag{ | ||
TaikoL1Address, | ||
TxGasLimit, | ||
PreconfAPIHTTPServerPort, | ||
BlobAllowed, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package preconfapi | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/taikoxyz/taiko-mono/packages/taiko-client/preconfapi/builder" | ||
"github.com/taikoxyz/taiko-mono/packages/taiko-client/preconfapi/server" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type PreconfAPI struct { | ||
*Config | ||
server *server.PreconfAPIServer | ||
} | ||
|
||
// InitFromCli New initializes the given proposer instance based on the command line flags. | ||
func (p *PreconfAPI) InitFromCli(ctx context.Context, c *cli.Context) error { | ||
cfg, err := NewConfigFromCliContext(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return p.InitFromConfig(ctx, cfg) | ||
} | ||
|
||
func (p *PreconfAPI) InitFromConfig(ctx context.Context, cfg *Config) (err error) { | ||
var txBuilder builder.TxBuilder | ||
if cfg.BlobAllowed { | ||
txBuilder = builder.NewBlobTransactionBuilder( | ||
cfg.TaikoL1Address, | ||
cfg.ProposeBlockTxGasLimit, | ||
) | ||
} else { | ||
// TODO: calldata builder | ||
} | ||
|
||
// Prover server | ||
if p.server, err = server.New(&server.NewPreconfAPIServerOpts{ | ||
TxBuilder: txBuilder, | ||
}); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *PreconfAPI) Start() error { | ||
go func() { | ||
if err := p.server.Start(fmt.Sprintf(":%v", p.HTTPPort)); !errors.Is(err, http.ErrServerClosed) { | ||
log.Crit("Failed to start http server", "error", err) | ||
} | ||
}() | ||
return nil | ||
} | ||
|
||
// Close closes the proposer instance. | ||
func (p *PreconfAPI) Close(ctx context.Context) { | ||
if err := p.server.Shutdown(ctx); err != nil { | ||
log.Error("Failed to shut down prover server", "error", err) | ||
} | ||
} | ||
|
||
func (p *PreconfAPI) Name() string { | ||
return "preconfapi" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum-optimism/optimism/op-service/eth" | ||
"github.com/ethereum-optimism/optimism/op-service/txmgr" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
|
||
"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings/encoding" | ||
"github.com/taikoxyz/taiko-mono/packages/taiko-client/internal/utils" | ||
) | ||
|
||
// BlobTransactionBuilder is responsible for building a TaikoL1.proposeBlock transaction with txList | ||
// bytes saved in blob. | ||
type BlobTransactionBuilder struct { | ||
taikoL1Address common.Address | ||
gasLimit uint64 | ||
} | ||
|
||
// NewBlobTransactionBuilder creates a new BlobTransactionBuilder instance based on giving configurations. | ||
func NewBlobTransactionBuilder( | ||
taikoL1Address common.Address, | ||
gasLimit uint64, | ||
) *BlobTransactionBuilder { | ||
return &BlobTransactionBuilder{ | ||
taikoL1Address, | ||
gasLimit, | ||
} | ||
} | ||
|
||
// BuildUnsigned implements the ProposeBlockTransactionBuilder interface to | ||
// return an unsigned transaction, intended for preconfirmations. | ||
func (b *BlobTransactionBuilder) BuildUnsigned( | ||
ctx context.Context, | ||
txListBytes []byte, | ||
l1StateBlockNumber uint32, | ||
timestamp uint64, | ||
coinbase common.Address, | ||
extraData [32]byte, | ||
) (*types.Transaction, error) { | ||
compressedTxListBytes, err := utils.Compress(txListBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var blob = ð.Blob{} | ||
if err := blob.FromData(compressedTxListBytes); err != nil { | ||
return nil, err | ||
} | ||
|
||
var ( | ||
to = &b.taikoL1Address | ||
data []byte | ||
) | ||
|
||
// ABI encode the TaikoL1.proposeBlock parameters. | ||
encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{ | ||
ExtraData: extraData, | ||
Coinbase: coinbase, | ||
Signature: []byte{}, // no longer checked | ||
L1StateBlockNumber: l1StateBlockNumber, | ||
Timestamp: timestamp, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data, err = encoding.TaikoL1ABI.Pack("proposeBlock", encodedParams, []byte{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
sidecar, blobHashes, err := txmgr.MakeSidecar([]*eth.Blob{blob}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
blobTx := &types.BlobTx{ | ||
To: *to, | ||
Value: nil, // maxFee / prover selecting no longer happens | ||
Gas: b.gasLimit, | ||
Data: data, | ||
Sidecar: sidecar, | ||
BlobHashes: blobHashes, | ||
} | ||
|
||
tx := types.NewTx(blobTx) | ||
|
||
return tx, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
// CalldataTransactionBuilder is responsible for building a TaikoL1.proposeBlock transaction with txList | ||
// bytes saved in blob. | ||
type CalldataTransactionBuilder struct { | ||
taikoL1Address common.Address | ||
gasLimit uint64 | ||
} | ||
|
||
// NewCalldataTransactionBuilder creates a new CalldataTransactionBuilder instance based on giving configurations. | ||
func NewCalldataTransactionBuilder( | ||
taikoL1Address common.Address, | ||
gasLimit uint64, | ||
) *CalldataTransactionBuilder { | ||
return &CalldataTransactionBuilder{ | ||
taikoL1Address, | ||
gasLimit, | ||
} | ||
} | ||
|
||
// BuildUnsigned implements the ProposeBlockTransactionBuilder interface to | ||
// return an unsigned transaction, intended for preconfirmations. | ||
func (b *CalldataTransactionBuilder) BuildUnsigned( | ||
_ context.Context, | ||
_ []byte, | ||
_ uint32, | ||
_ uint64, | ||
_ common.Address, | ||
_ [32]byte, | ||
) (*types.Transaction, error) { | ||
return &types.Transaction{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
) | ||
|
||
type TxBuilder interface { | ||
BuildUnsigned( | ||
ctx context.Context, | ||
txListBytes []byte, | ||
l1StateBlockNumber uint32, | ||
timestamp uint64, | ||
coinbase common.Address, | ||
extraData [32]byte, | ||
) (*types.Transaction, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package preconfapi | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/taikoxyz/taiko-mono/packages/taiko-client/cmd/flags" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
type Config struct { | ||
TaikoL1Address common.Address | ||
BlobAllowed bool | ||
HTTPPort uint64 | ||
ProposeBlockTxGasLimit uint64 | ||
} | ||
|
||
// NewConfigFromCliContext initializes a Config instance from | ||
// command line flags. | ||
func NewConfigFromCliContext(c *cli.Context) (*Config, error) { | ||
return &Config{ | ||
TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)), | ||
BlobAllowed: c.Bool(flags.BlobAllowed.Name), | ||
HTTPPort: c.Uint64(flags.PreconfAPIHTTPServerPort.Name), | ||
ProposeBlockTxGasLimit: c.Uint64(flags.TxGasLimit.Name), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.