Skip to content

Commit

Permalink
rlp: add WriteString method on EncoderBuffer (ethereum#24425)
Browse files Browse the repository at this point in the history
rlpgen outputs calls to this method for values of type string.
  • Loading branch information
ucwong authored and gurukamath committed Feb 27, 2022
1 parent 0cb4d65 commit d45f420
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 13 additions & 2 deletions core/genesis.go
Expand Up @@ -44,6 +44,12 @@ import (

var errGenesisNoConfig = errors.New("genesis has no chain configuration")

// Various checks on genesis extradata
var (
extraVanity = 32 // Fixed number of extra-data prefix bytes reserved for signer vanity
extraSeal = crypto.SignatureLength // Fixed number of extra-data suffix bytes reserved for signer seal
)

// Genesis specifies the header fields, state of a genesis block. It also defines hard
// fork switch-over blocks through the chain configuration.
type Genesis struct {
Expand Down Expand Up @@ -324,8 +330,13 @@ func (g *Genesis) Commit(db ethdb.Database) (*types.Block, error) {
if err := config.CheckConfigForkOrder(); err != nil {
return nil, err
}
if config.Clique != nil && len(block.Extra()) == 0 {
return nil, errors.New("can't start clique chain without signers")
if config.Clique != nil {
if len(block.Extra()) < extraVanity {
return nil, errors.New("extra-data 32 byte vanity prefix missing")
}
if len(block.Extra()) < extraVanity+extraSeal {
return nil, errors.New("extra-data 65 byte signature suffix missing")
}
}
rawdb.WriteTd(db, block.Hash(), block.NumberU64(), block.Difficulty())
rawdb.WriteBlock(db, block)
Expand Down
9 changes: 9 additions & 0 deletions rlp/encbuffer.go
Expand Up @@ -118,6 +118,10 @@ func (buf *encBuffer) writeBytes(b []byte) {
}
}

func (buf *encBuffer) writeString(s string) {
buf.writeBytes([]byte(s))
}

// wordBytes is the number of bytes in a big.Word
const wordBytes = (32 << (uint64(^big.Word(0)) >> 63)) / 8

Expand Down Expand Up @@ -340,6 +344,11 @@ func (w EncoderBuffer) WriteBytes(b []byte) {
w.buf.writeBytes(b)
}

// WriteBytes encodes s as an RLP string.
func (w EncoderBuffer) WriteString(s string) {
w.buf.writeString(s)
}

// List starts a list. It returns an internal index. Call EndList with
// this index after encoding the content to finish the list.
func (w EncoderBuffer) List() int {
Expand Down

0 comments on commit d45f420

Please sign in to comment.