mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
cmd/evm/internal: add Codeword and CodeLength on block header struct
This commit is contained in:
parent
e5a24bdf69
commit
fc1e51c4cb
3 changed files with 66 additions and 4 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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.",
|
||||
|
|
|
|||
|
|
@ -34,6 +34,9 @@ func (h header) MarshalJSON() ([]byte, error) {
|
|||
MixDigest common.Hash `json:"mixHash"`
|
||||
Nonce *types.BlockNonce `json:"nonce"`
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
@ -74,6 +79,8 @@ func (h *header) UnmarshalJSON(input []byte) error {
|
|||
MixDigest *common.Hash `json:"mixHash"`
|
||||
Nonce *types.BlockNonce `json:"nonce"`
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue