Commit 23c658d6 authored by Tei Im's avatar Tei Im

Apply suggestions from code reviews

Fix comments
Check if the span batch is empty in LogContext()
Check chain ID of the protected tx in newSpanBatchTxs()
Write SpanBatchType explicitly when encoding span batch
parent d6e1259b
......@@ -72,7 +72,7 @@ func (b *BatchData) encodeTyped(buf *bytes.Buffer) error {
buf.WriteByte(SingularBatchType)
return rlp.Encode(buf, &b.SingularBatch)
case SpanBatchType:
buf.WriteByte(byte(b.BatchType))
buf.WriteByte(SpanBatchType)
return b.RawSpanBatch.encode(buf)
default:
return fmt.Errorf("unrecognized batch type: %d", b.BatchType)
......
......@@ -10,7 +10,7 @@ import (
// FuzzBatchRoundTrip executes a fuzz test similar to TestBatchRoundTrip, which tests that arbitrary BatchData will be
// encoded and decoded without loss of its original values.
// Does not test span batch because fuzzer is not aware structure of span batch.
// Does not test the span batch type because the fuzzer is not aware of the structure of a span batch.
func FuzzBatchRoundTrip(f *testing.F) {
f.Fuzz(func(t *testing.T, fuzzedData []byte) {
// Create our fuzzer wrapper to generate complex values
......
......@@ -22,8 +22,8 @@ import (
// SpanBatchType := 1
// spanBatch := SpanBatchType ++ prefix ++ payload
// prefix := rel_timestamp ++ l1_origin_num ++ parent_check ++ l1_origin_check
// payload := payload = block_count ++ origin_bits ++ block_tx_counts ++ txs
// txs = contract_creation_bits ++ y_parity_bits ++ tx_sigs ++ tx_tos ++ tx_datas ++ tx_nonces ++ tx_gases
// payload := block_count ++ origin_bits ++ block_tx_counts ++ txs
// txs := contract_creation_bits ++ y_parity_bits ++ tx_sigs ++ tx_tos ++ tx_datas ++ tx_nonces ++ tx_gases
var ErrTooBigSpanBatchFieldSize = errors.New("batch would cause field bytes to go over limit")
......@@ -433,6 +433,9 @@ func (b *SpanBatch) GetTimestamp() uint64 {
// LogContext creates a new log context that contains information of the batch
func (b *SpanBatch) LogContext(log log.Logger) log.Logger {
if len(b.batches) == 0 {
return log.New("block_count", 0)
}
return log.New(
"batch_timestamp", b.batches[0].Timestamp,
"parent_check", hexutil.Encode(b.parentCheck),
......
......@@ -432,6 +432,9 @@ func newSpanBatchTxs(txs [][]byte, chainID *big.Int) (*spanBatchTxs, error) {
if err := tx.UnmarshalBinary(txs[idx]); err != nil {
return nil, errors.New("failed to decode tx")
}
if tx.Protected() && tx.ChainId().Cmp(chainID) != 0 {
return nil, fmt.Errorf("protected tx has chain ID %d, but expected chain ID %d", tx.ChainId(), chainID)
}
var txSig spanBatchSignature
v, r, s := tx.RawSignatureValues()
R, _ := uint256.FromBig(r)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment