From fc1e51c4cb329ee4f31f93a7f2799927ea037944 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 23 Apr 2024 13:02:08 +0900 Subject: [PATCH] cmd/evm/internal: add Codeword and CodeLength on block header struct --- cmd/evm/internal/t8ntool/block.go | 49 ++++++++++++++++++++++++-- cmd/evm/internal/t8ntool/flags.go | 4 +++ cmd/evm/internal/t8ntool/gen_header.go | 17 +++++++-- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/cmd/evm/internal/t8ntool/block.go b/cmd/evm/internal/t8ntool/block.go index 8f9156330c..714d2fe747 100644 --- a/cmd/evm/internal/t8ntool/block.go +++ b/cmd/evm/internal/t8ntool/block.go @@ -55,6 +55,8 @@ type header struct { MixDigest common.Hash `json:"mixHash"` Nonce *types.BlockNonce `json:"nonce"` BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"` + Codeword []byte `json:"codeword" rlp:"optional"` + CodeLength uint64 `json:"codelength" rlp:"optional"` } type headerMarshaling struct { @@ -78,6 +80,9 @@ type bbInput struct { PowMode ethash.Mode `json:"-"` Txs []*types.Transaction `json:"-"` Ommers []*types.Header `json:"-"` + + //eccpow + Eccpow bool `json:"-"` } type cliqueInput struct { @@ -154,6 +159,13 @@ func (i *bbInput) ToBlock() *types.Block { if header.Difficulty != nil { header.Difficulty = i.Header.Difficulty } + if header.Codeword != nil { + header.Codeword = i.Header.Codeword + } + if header.CodeLength != 0 { + header.CodeLength = i.Header.CodeLength + } + return types.NewBlockWithHeader(header).WithBody(i.Txs, i.Ommers) } @@ -162,6 +174,8 @@ func (i *bbInput) SealBlock(block *types.Block) (*types.Block, error) { switch { case i.Ethash: return i.sealEthash(block) + case i.Eccpow: + return i.sealEccpow(block) case i.Clique != nil: return i.sealClique(block) default: @@ -196,6 +210,29 @@ func (i *bbInput) sealEthash(block *types.Block) (*types.Block, error) { return block.WithSeal(found.Header()), nil } +// sealEccpow seals the given block using eccpow !!to update +func (i *bbInput) sealEccpow(block *types.Block) (*types.Block, error) { + if i.Header.Nonce != nil { + return nil, NewError(ErrorConfig, fmt.Errorf("sealing with eccpow will overwrite provided nonce")) + } + + //!!true or false? // eccpow + engine := eccpow.New(eccpow.Config{}, nil, true) + defer engine.Close() + // Use a buffered chan for results. + // If the testmode is used, the sealer will return quickly, and complain + // "Sealing result is not read by miner" if it cannot write the result. + results := make(chan *types.Block, 1) + if err := engine.Seal(nil, block, results, nil); err != nil { + panic(fmt.Sprintf("failed to seal block: %v", err)) + } + found := <-results + + //copy codeword? + return block.WithSeal(found.Header()), nil +} + + // sealClique seals the given block using clique. func (i *bbInput) sealClique(block *types.Block) (*types.Block, error) { // If any clique value overwrites an explicit header value, fail @@ -264,13 +301,19 @@ func readInput(ctx *cli.Context) (*bbInput, error) { ommersStr = ctx.String(InputOmmersFlag.Name) txsStr = ctx.String(InputTxsRlpFlag.Name) cliqueStr = ctx.String(SealCliqueFlag.Name) + eccpowOn = ctx.Bool(SealEccpowFlag.Name) ethashOn = ctx.Bool(SealEthashFlag.Name) ethashDir = ctx.String(SealEthashDirFlag.Name) ethashMode = ctx.String(SealEthashModeFlag.Name) inputData = &bbInput{} ) - if ethashOn && cliqueStr != "" { - return nil, NewError(ErrorConfig, fmt.Errorf("both ethash and clique sealing specified, only one may be chosen")) + + //need to update. + if ethashOn && eccpowOn && cliqueStr != "" { + return nil, NewError(ErrorConfig, fmt.Errorf("ethash and clique, eccpow sealing specified, only one may be chosen")) +} + if eccpowOn { + inputData.Eccpow = eccpowOn } if ethashOn { inputData.Ethash = ethashOn @@ -292,6 +335,8 @@ func readInput(ctx *cli.Context) (*bbInput, error) { return nil, NewError(ErrorJson, fmt.Errorf("failed unmarshaling stdin: %v", err)) } } + + if cliqueStr != stdinSelector && cliqueStr != "" { var clique cliqueInput if err := readFile(cliqueStr, "clique", &clique); err != nil { diff --git a/cmd/evm/internal/t8ntool/flags.go b/cmd/evm/internal/t8ntool/flags.go index d2280d65af..2672f93aa3 100644 --- a/cmd/evm/internal/t8ntool/flags.go +++ b/cmd/evm/internal/t8ntool/flags.go @@ -121,6 +121,10 @@ var ( Name: "seal.clique", Usage: "Seal block with Clique. `stdin` or file name of where to find the Clique sealing data.", } + SealEccpowFlag = &cli.StringFlag{ + Name: "seal.eccpow", + Usage: "Seal block with eccpow.", + } SealEthashFlag = &cli.BoolFlag{ Name: "seal.ethash", Usage: "Seal block with ethash.", diff --git a/cmd/evm/internal/t8ntool/gen_header.go b/cmd/evm/internal/t8ntool/gen_header.go index 6609277fdf..addd90cc91 100644 --- a/cmd/evm/internal/t8ntool/gen_header.go +++ b/cmd/evm/internal/t8ntool/gen_header.go @@ -33,7 +33,10 @@ func (h header) MarshalJSON() ([]byte, error) { Extra hexutil.Bytes `json:"extraData"` MixDigest common.Hash `json:"mixHash"` Nonce *types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"` + Codeword hexutil.Bytes `json:"codeword" rlp:"optional"` + CodeLength math.HexOrDecimal64 `json:"codelength" rlp:"optional"` + } var enc header enc.ParentHash = h.ParentHash @@ -52,6 +55,8 @@ func (h header) MarshalJSON() ([]byte, error) { enc.MixDigest = h.MixDigest enc.Nonce = h.Nonce enc.BaseFee = (*math.HexOrDecimal256)(h.BaseFee) + enc.Codeword = h.Codeword + enc.CodeLength = math.HexOrDecimal64(h.CodeLength) return json.Marshal(&enc) } @@ -73,7 +78,9 @@ func (h *header) UnmarshalJSON(input []byte) error { Extra *hexutil.Bytes `json:"extraData"` MixDigest *common.Hash `json:"mixHash"` Nonce *types.BlockNonce `json:"nonce"` - BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"` + BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas" rlp:"optional"` + Codeword *hexutil.Bytes `json:"codeword" rlp:"optional"` + CodeLength *math.HexOrDecimal64 `json:"codelength" rlp:"optional"` } var dec header if err := json.Unmarshal(input, &dec); err != nil { @@ -131,5 +138,11 @@ func (h *header) UnmarshalJSON(input []byte) error { if dec.BaseFee != nil { h.BaseFee = (*big.Int)(dec.BaseFee) } + if dec.Codeword != nil { + h.Codeword = *dec.Codeword + } + if dec.CodeLength != nil { + h.CodeLength = uint64(*dec.CodeLength) + } return nil }