Use type string for total_difficulty (#10265)

* Use string for difficulty

* fix go

* fix test

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
This commit is contained in:
terence tsao
2022-02-21 06:03:12 -08:00
committed by GitHub
parent 7f41b69281
commit a55fdf8949
5 changed files with 12 additions and 20 deletions

View File

@@ -563,7 +563,7 @@ func fixtures() map[string]interface{} {
ReceiptsRoot: receiptsRoot,
LogsBloom: logsBloom,
Difficulty: bytesutil.PadTo([]byte("1"), fieldparams.RootLength),
TotalDifficulty: bytesutil.PadTo([]byte("2"), fieldparams.RootLength),
TotalDifficulty: "2",
GasLimit: 3,
GasUsed: 4,
Timestamp: 5,

View File

@@ -98,7 +98,7 @@ type ExecutionBlock struct {
ReceiptsRoot []byte `protobuf:"bytes,8,opt,name=receipts_root,json=receiptsRoot,proto3" json:"receipts_root,omitempty"`
LogsBloom []byte `protobuf:"bytes,9,opt,name=logs_bloom,json=logsBloom,proto3" json:"logs_bloom,omitempty"`
Difficulty []byte `protobuf:"bytes,10,opt,name=difficulty,proto3" json:"difficulty,omitempty"`
TotalDifficulty []byte `protobuf:"bytes,11,opt,name=total_difficulty,json=totalDifficulty,proto3" json:"total_difficulty,omitempty"`
TotalDifficulty string `protobuf:"bytes,11,opt,name=total_difficulty,json=totalDifficulty,proto3" json:"total_difficulty,omitempty"`
GasLimit uint64 `protobuf:"varint,12,opt,name=gas_limit,json=gasLimit,proto3" json:"gas_limit,omitempty"`
GasUsed uint64 `protobuf:"varint,13,opt,name=gas_used,json=gasUsed,proto3" json:"gas_used,omitempty"`
BaseFeePerGas []byte `protobuf:"bytes,14,opt,name=base_fee_per_gas,json=baseFeePerGas,proto3" json:"base_fee_per_gas,omitempty"`
@@ -213,11 +213,11 @@ func (x *ExecutionBlock) GetDifficulty() []byte {
return nil
}
func (x *ExecutionBlock) GetTotalDifficulty() []byte {
func (x *ExecutionBlock) GetTotalDifficulty() string {
if x != nil {
return x.TotalDifficulty
}
return nil
return ""
}
func (x *ExecutionBlock) GetGasLimit() uint64 {
@@ -723,7 +723,7 @@ var file_proto_engine_v1_execution_engine_proto_rawDesc = []byte{
0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x18, 0x0a,
0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79,
0x12, 0x29, 0x0a, 0x10, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x5f, 0x64, 0x69, 0x66, 0x66, 0x69, 0x63,
0x75, 0x6c, 0x74, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61,
0x75, 0x6c, 0x74, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x74, 0x6f, 0x74, 0x61,
0x6c, 0x44, 0x69, 0x66, 0x66, 0x69, 0x63, 0x75, 0x6c, 0x74, 0x79, 0x12, 0x1b, 0x0a, 0x09, 0x67,
0x61, 0x73, 0x5f, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08,
0x67, 0x61, 0x73, 0x4c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x67, 0x61, 0x73, 0x5f,

View File

@@ -35,10 +35,10 @@ message ExecutionBlock {
bytes receipts_root = 8;
bytes logs_bloom = 9;
bytes difficulty = 10;
bytes total_difficulty = 11;
string total_difficulty = 11;
uint64 gas_limit = 12;
uint64 gas_used = 13;
bytes base_fee_per_gas = 14;
bytes base_fee_per_gas = 14;
bytes size = 15;
uint64 timestamp = 16;
bytes extra_data = 17;

View File

@@ -71,9 +71,6 @@ func (e *ExecutionBlock) MarshalJSON() ([]byte, error) {
diff := new(big.Int).SetBytes(e.Difficulty)
diffHex := hexutil.EncodeBig(diff)
totalDiff := new(big.Int).SetBytes(e.TotalDifficulty)
totalDiffHex := hexutil.EncodeBig(totalDiff)
size := new(big.Int).SetBytes(e.Size)
sizeHex := hexutil.EncodeBig(size)
@@ -90,7 +87,7 @@ func (e *ExecutionBlock) MarshalJSON() ([]byte, error) {
ReceiptsRoot: e.ReceiptsRoot,
LogsBloom: e.LogsBloom,
Difficulty: diffHex,
TotalDifficulty: totalDiffHex,
TotalDifficulty: e.TotalDifficulty,
GasLimit: hexutil.Uint64(e.GasLimit),
GasUsed: hexutil.Uint64(e.GasUsed),
Timestamp: hexutil.Uint64(e.Timestamp),
@@ -130,11 +127,7 @@ func (e *ExecutionBlock) UnmarshalJSON(enc []byte) error {
return err
}
e.Difficulty = diff.Bytes()
totalDiff, err := hexutil.DecodeBig(dec.TotalDifficulty)
if err != nil {
return err
}
e.TotalDifficulty = totalDiff.Bytes()
e.TotalDifficulty = dec.TotalDifficulty
e.GasLimit = uint64(dec.GasLimit)
e.GasUsed = uint64(dec.GasUsed)
e.Timestamp = uint64(dec.Timestamp)

View File

@@ -79,7 +79,6 @@ func TestJsonMarshalUnmarshal(t *testing.T) {
})
t.Run("execution payload", func(t *testing.T) {
baseFeePerGas := big.NewInt(6)
baseFeePerGasBytes := bytesutil.ReverseByteOrder(baseFeePerGas.Bytes())
parentHash := bytesutil.PadTo([]byte("parent"), fieldparams.RootLength)
feeRecipient := bytesutil.PadTo([]byte("feeRecipient"), fieldparams.FeeRecipientLength)
stateRoot := bytesutil.PadTo([]byte("stateRoot"), fieldparams.RootLength)
@@ -100,7 +99,7 @@ func TestJsonMarshalUnmarshal(t *testing.T) {
GasUsed: 3,
Timestamp: 4,
ExtraData: extra,
BaseFeePerGas: baseFeePerGasBytes,
BaseFeePerGas: baseFeePerGas.Bytes(),
BlockHash: hash,
Transactions: [][]byte{[]byte("hi")},
}
@@ -135,7 +134,7 @@ func TestJsonMarshalUnmarshal(t *testing.T) {
ReceiptsRoot: []byte("receiptsRoot"),
LogsBloom: []byte("logsBloom"),
Difficulty: []byte("1"),
TotalDifficulty: []byte("2"),
TotalDifficulty: "2",
GasLimit: 3,
GasUsed: 4,
Timestamp: 5,
@@ -161,7 +160,7 @@ func TestJsonMarshalUnmarshal(t *testing.T) {
require.DeepEqual(t, []byte("receiptsRoot"), payloadPb.ReceiptsRoot)
require.DeepEqual(t, []byte("logsBloom"), payloadPb.LogsBloom)
require.DeepEqual(t, []byte("1"), payloadPb.Difficulty)
require.DeepEqual(t, []byte("2"), payloadPb.TotalDifficulty)
require.DeepEqual(t, "2", payloadPb.TotalDifficulty)
require.DeepEqual(t, uint64(3), payloadPb.GasLimit)
require.DeepEqual(t, uint64(4), payloadPb.GasUsed)
require.DeepEqual(t, uint64(5), payloadPb.Timestamp)