Skip to content

Commit

Permalink
Fix/l2 block nonce (0xPolygonHermez#3008)
Browse files Browse the repository at this point in the history
  • Loading branch information
tclemos authored Jan 2, 2024
1 parent 11fcd73 commit 05363e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 22 deletions.
11 changes: 4 additions & 7 deletions jsonrpc/endpoints_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,13 +1222,8 @@ func TestGetL2BlockByNumber(t *testing.T) {
miner = &cb
}

var rpcBlockNonce *types.ArgBytes
if l2Block.Nonce() > 0 {
nBig := big.NewInt(0).SetUint64(l2Block.Nonce())
nBytes := common.LeftPadBytes(nBig.Bytes(), 8) //nolint:gomnd
n := types.ArgBytes(nBytes)
rpcBlockNonce = &n
}
n := big.NewInt(0).SetUint64(l2Block.Nonce())
rpcBlockNonce := common.LeftPadBytes(n.Bytes(), 8) //nolint:gomnd

difficulty := types.ArgUint64(0)
var totalDifficulty *types.ArgUint64
Expand Down Expand Up @@ -1413,6 +1408,8 @@ func TestGetL2BlockByNumber(t *testing.T) {
tc.ExpectedResult.Sha3Uncles = ethTypes.EmptyUncleHash
tc.ExpectedResult.Size = 501
tc.ExpectedResult.ExtraData = []byte{}
rpcBlockNonce := common.LeftPadBytes(big.NewInt(0).Bytes(), 8) //nolint:gomnd
tc.ExpectedResult.Nonce = rpcBlockNonce

m.DbTx.
On("Commit", context.Background()).
Expand Down
11 changes: 4 additions & 7 deletions jsonrpc/endpoints_zkevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,13 +1429,8 @@ func TestGetL2FullBlockByNumber(t *testing.T) {
miner = &cb
}

var rpcBlockNonce *types.ArgBytes
if l2Block.Nonce() > 0 {
nBig := big.NewInt(0).SetUint64(l2Block.Nonce())
nBytes := common.LeftPadBytes(nBig.Bytes(), 8) //nolint:gomnd
n := types.ArgBytes(nBytes)
rpcBlockNonce = &n
}
n := big.NewInt(0).SetUint64(l2Block.Nonce())
rpcBlockNonce := common.LeftPadBytes(n.Bytes(), 8) //nolint:gomnd

difficulty := types.ArgUint64(0)
var totalDifficulty *types.ArgUint64
Expand Down Expand Up @@ -1622,6 +1617,8 @@ func TestGetL2FullBlockByNumber(t *testing.T) {
tc.ExpectedResult.Sha3Uncles = ethTypes.EmptyUncleHash
tc.ExpectedResult.Size = 501
tc.ExpectedResult.ExtraData = []byte{}
rpcBlockNonce := common.LeftPadBytes(big.NewInt(0).Bytes(), 8) //nolint:gomnd
tc.ExpectedResult.Nonce = rpcBlockNonce

m.DbTx.
On("Commit", context.Background()).
Expand Down
11 changes: 3 additions & 8 deletions jsonrpc/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ type Block struct {
Timestamp ArgUint64 `json:"timestamp"`
ExtraData ArgBytes `json:"extraData"`
MixHash common.Hash `json:"mixHash"`
Nonce *ArgBytes `json:"nonce"`
Nonce ArgBytes `json:"nonce"`
Hash *common.Hash `json:"hash"`
Transactions []TransactionOrHash `json:"transactions"`
Uncles []common.Hash `json:"uncles"`
Expand All @@ -273,13 +273,8 @@ func NewBlock(hash *common.Hash, b *state.L2Block, receipts []types.Receipt, ful
miner = &cb
}

var nonce *ArgBytes
if h.Nonce.Uint64() > 0 {
nBig := big.NewInt(0).SetUint64(h.Nonce.Uint64())
nBytes := common.LeftPadBytes(nBig.Bytes(), 8) //nolint:gomnd
n := ArgBytes(nBytes)
nonce = &n
}
n := big.NewInt(0).SetUint64(h.Nonce.Uint64())
nonce := common.LeftPadBytes(n.Bytes(), 8) //nolint:gomnd

difficulty := ArgUint64(0)
var totalDifficulty *ArgUint64
Expand Down

0 comments on commit 05363e5

Please sign in to comment.