Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC update - add l2 gas #2335

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ func AdaptSignature(sig []*felt.Felt) *gen.ConsensusSignature {
func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
stateDiffCommitment *felt.Felt, stateDiffLength uint64,
) *gen.SignedBlockHeader {
var l2GasPriceSTRK, l2GasPriceETH *felt.Felt

if header.L2GasPriceSTRK != nil {
l2GasPriceSTRK = header.L2GasPriceSTRK
} else {
l2GasPriceSTRK = &felt.Zero
}

if header.L2GasPriceETH != nil {
l2GasPriceETH = header.L2GasPriceETH
} else {
l2GasPriceETH = &felt.Zero
}

return &gen.SignedBlockHeader{
BlockHash: AdaptHash(header.Hash),
ParentHash: AdaptHash(header.ParentHash),
Expand All @@ -47,16 +61,18 @@ func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
},
Receipts: AdaptHash(commitments.ReceiptCommitment),
ProtocolVersion: header.ProtocolVersion,
GasPriceFri: AdaptUint128(header.GasPriceSTRK),
L1GasPriceFri: AdaptUint128(header.L1GasPriceSTRK),
Signatures: utils.Map(header.Signatures, AdaptSignature),
StateDiffCommitment: &gen.StateDiffCommitment{
StateDiffLength: stateDiffLength,
Root: AdaptHash(stateDiffCommitment),
},
GasPriceWei: AdaptUint128(header.GasPrice),
DataGasPriceFri: AdaptUint128(header.L1DataGasPrice.PriceInFri),
DataGasPriceWei: AdaptUint128(header.L1DataGasPrice.PriceInWei),
L1GasPriceWei: AdaptUint128(header.L1GasPriceETH),
L1DataGasPriceFri: AdaptUint128(header.L1DataGasPrice.PriceInFri),
L1DataGasPriceWei: AdaptUint128(header.L1DataGasPrice.PriceInWei),
L1DataAvailabilityMode: adaptL1DA(header.L1DAMode),
L2GasPriceFri: AdaptUint128(l2GasPriceSTRK),
L2GasPriceWei: AdaptUint128(l2GasPriceETH),
}
}

Expand Down
4 changes: 3 additions & 1 deletion adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
return nil
}

var l1Gas, l1DataGas, totalL1Gas *felt.Felt
var l1Gas, l2Gas, l1DataGas, totalL1Gas *felt.Felt
if da := er.DataAvailability; da != nil { // todo(kirill) check that it might be null
l1Gas = new(felt.Felt).SetUint64(da.L1Gas)
l2Gas = new(felt.Felt).SetUint64(da.L2Gas)
l1DataGas = new(felt.Felt).SetUint64(da.L1DataGas)
}
if tgs := er.TotalGasConsumed; tgs != nil {
Expand All @@ -129,6 +130,7 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
L1Gas: AdaptFelt(l1Gas),
L2Gas: AdaptFelt(l2Gas),
L1DataGas: AdaptFelt(l1DataGas),
TotalL1Gas: AdaptFelt(totalL1Gas),
}
Expand Down
5 changes: 3 additions & 2 deletions adapters/core2p2p/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ func adaptResourceLimits(bounds core.ResourceBounds) *gen.ResourceLimits {

func adaptResourceBounds(rb map[core.Resource]core.ResourceBounds) *gen.ResourceBounds {
return &gen.ResourceBounds{
L1Gas: adaptResourceLimits(rb[core.ResourceL1Gas]),
L2Gas: adaptResourceLimits(rb[core.ResourceL2Gas]),
L1Gas: adaptResourceLimits(rb[core.ResourceL1Gas]),
L1DataGas: adaptResourceLimits(rb[core.ResourceL1DataGas]),
L2Gas: adaptResourceLimits(rb[core.ResourceL2Gas]),
}
}

Expand Down
15 changes: 10 additions & 5 deletions adapters/p2p2core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ func AdaptBlockHeader(h *gen.SignedBlockHeader, eventsBloom *bloom.BloomFilter)
Timestamp: h.Time,
ProtocolVersion: h.ProtocolVersion,
EventsBloom: eventsBloom,
L1GasPriceETH: AdaptUint128(h.L1GasPriceWei),
L2GasPriceETH: AdaptUint128(h.L2GasPriceWei),
Signatures: utils.Map(h.Signatures, adaptSignature),
L1GasPriceSTRK: AdaptUint128(h.L1GasPriceFri),
L2GasPriceSTRK: AdaptUint128(h.L2GasPriceFri),
L1DAMode: adaptDA(h.L1DataAvailabilityMode),
L1DataGasPrice: &core.GasPrice{
PriceInWei: AdaptUint128(h.DataGasPriceWei),
PriceInFri: AdaptUint128(h.DataGasPriceFri),
PriceInWei: AdaptUint128(h.L1DataGasPriceWei),
PriceInFri: AdaptUint128(h.L1DataGasPriceFri),
},
L2GasPrice: &core.GasPrice{
PriceInWei: AdaptUint128(h.L2GasPriceWei),
PriceInFri: AdaptUint128(h.L2GasPriceFri),
},
GasPrice: AdaptUint128(h.GasPriceWei),
GasPriceSTRK: AdaptUint128(h.GasPriceFri),
L2GasPrice: nil, // todo pass correct value once it's in the p2p spec
}
}

Expand Down
2 changes: 2 additions & 0 deletions adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ func adaptExecutionResources(er *gen.Receipt_ExecutionResources) *core.Execution
},
DataAvailability: &core.DataAvailability{
L1Gas: feltToUint64(er.L1Gas),
L2Gas: feltToUint64(er.L2Gas),
L1DataGas: feltToUint64(er.L1DataGas),
},
MemoryHoles: uint64(er.MemoryHoles),
Steps: uint64(er.Steps), // todo SPEC 32 -> 64 bytes
TotalGasConsumed: &core.GasConsumed{
L1Gas: feltToUint64(er.TotalL1Gas),
L2Gas: feltToUint64(er.L2Gas),
// total_l1_data_gas = l1_data_gas, because there's only one place that can generate l1_data_gas costs
L1DataGas: feltToUint64(er.L1DataGas),
},
Expand Down
7 changes: 5 additions & 2 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ func AdaptBlock(response *starknet.Block, sig *starknet.Signature) (*core.Block,
TransactionCount: uint64(len(response.Transactions)),
EventCount: eventCount,
EventsBloom: core.EventsBloom(receipts),
GasPrice: response.GasPriceETH(),
GasPriceSTRK: response.GasPriceSTRK(),
L1GasPriceETH: response.L1GasPriceETH(),
L2GasPriceETH: response.L2GasPriceETH(),
L1GasPriceSTRK: response.L1GasPriceSTRK(),
L2GasPriceSTRK: response.L2GasPriceSTRK(),
L1DAMode: core.L1DAMode(response.L1DAMode),
L1DataGasPrice: (*core.GasPrice)(response.L1DataGasPrice),
L2GasPrice: (*core.GasPrice)(response.L2GasPrice),
Expand Down Expand Up @@ -88,6 +90,7 @@ func adaptGasConsumed(response *starknet.GasConsumed) *core.GasConsumed {
return &core.GasConsumed{
L1Gas: response.L1Gas,
L1DataGas: response.L1DataGas,
L2Gas: response.L2Gas,
}
}

Expand Down
6 changes: 4 additions & 2 deletions adapters/sn2core/sn2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ func TestAdaptBlock(t *testing.T) {
assert.Empty(t, block.Signatures)
}

assert.Equal(t, test.gasPriceSTRK, block.GasPriceSTRK)
assert.Equal(t, test.gasPriceWEI, block.GasPrice)
assert.Equal(t, test.gasPriceSTRK, block.L1GasPriceSTRK)
assert.Equal(t, test.gasPriceWEI, block.L1GasPriceETH)
assert.Equal(t, &felt.Zero, block.L2GasPriceSTRK)
assert.Equal(t, &felt.Zero, block.L2GasPriceETH)
if test.l1DAGasPriceFRI != nil {
assert.Equal(t, test.l1DAGasPriceFRI, block.L1DataGasPrice.PriceInFri)
}
Expand Down
12 changes: 6 additions & 6 deletions clients/feeder/feeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestBlockWithoutSequencerAddressUnmarshal(t *testing.T) {
assert.Equal(t, uint64(11817), block.Number)
assert.Equal(t, "0x3df24be7b5fed6b41de08d38686b6142944119ca2a345c38793590d6804bba4", block.StateRoot.String())
assert.Equal(t, "ACCEPTED_ON_L2", block.Status)
assert.Equal(t, "0x27ad16775", block.GasPriceETH().String())
assert.Equal(t, "0x27ad16775", block.L1GasPriceETH().String())
assert.Equal(t, 52, len(block.Transactions))
assert.Equal(t, 52, len(block.Receipts))
assert.Equal(t, uint64(1669465009), block.Timestamp)
Expand All @@ -291,7 +291,7 @@ func TestBlockWithSequencerAddressUnmarshal(t *testing.T) {
assert.Equal(t, uint64(19199), block.Number)
assert.Equal(t, "0x541b796ea02703d02ff31459815f65f410ceefe80a4e3499f7ef9ccc36d26ee", block.StateRoot.String())
assert.Equal(t, "ACCEPTED_ON_L2", block.Status)
assert.Equal(t, "0x31c4e2d75", block.GasPriceETH().String())
assert.Equal(t, "0x31c4e2d75", block.L1GasPriceETH().String())
assert.Equal(t, 324, len(block.Transactions))
assert.Equal(t, 324, len(block.Receipts))
assert.Equal(t, uint64(1674728186), block.Timestamp)
Expand All @@ -309,8 +309,8 @@ func TestBlockHeaderV013Unmarshal(t *testing.T) {
require.Equal(t, uint64(319132), block.Number)
require.Equal(t, utils.HexToFelt(t, "0x2a6b9a8b60e1de80dc50e6b704b415a38e8fd03d82244cec92cbff0821a8975"), block.StateRoot)
require.Equal(t, "ACCEPTED_ON_L2", block.Status)
require.Equal(t, utils.HexToFelt(t, "0x3b9aca08"), block.GasPriceETH())
require.Equal(t, utils.HexToFelt(t, "0x2540be400"), block.GasPriceSTRK())
require.Equal(t, utils.HexToFelt(t, "0x3b9aca08"), block.L1GasPriceETH())
require.Equal(t, utils.HexToFelt(t, "0x2540be400"), block.L1GasPriceSTRK())
require.Equal(t, uint64(1700075354), block.Timestamp)
require.Equal(t, utils.HexToFelt(t, "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"), block.SequencerAddress)
require.Equal(t, "0.13.0", block.Version)
Expand All @@ -324,8 +324,8 @@ func TestBlockHeaderV0131Unmarshal(t *testing.T) {
require.Equal(t, utils.HexToFelt(t, "0x8ab8117e952f95efd96de0bc66dc6f13fe68dfda14b95fe1972759dee283a8"), block.Hash)
require.Equal(t, utils.HexToFelt(t, "0x13367121d0b7e34a9b10c8a5a1c269811cd9afc3ce680c88888f1a22d2f017a"), block.TransactionCommitment)
require.Equal(t, utils.HexToFelt(t, "0x1090dd2ab2aa22bd5fc5a59d3b1394d54461bb2a80156c4b2c2622d2c474ca2"), block.EventCommitment)
require.Equal(t, utils.HexToFelt(t, "0x3b9aca0a"), block.GasPriceETH())
require.Equal(t, utils.HexToFelt(t, "0x2b6fdb70"), block.GasPriceSTRK())
require.Equal(t, utils.HexToFelt(t, "0x3b9aca0a"), block.L1GasPriceETH())
require.Equal(t, utils.HexToFelt(t, "0x2b6fdb70"), block.L1GasPriceSTRK())
require.Equal(t, utils.HexToFelt(t, "0x5265a14ef"), block.L1DataGasPrice.PriceInWei)
require.Equal(t, utils.HexToFelt(t, "0x3c0c00c87"), block.L1DataGasPrice.PriceInFri)
require.Equal(t, starknet.Blob, block.L1DAMode)
Expand Down
26 changes: 15 additions & 11 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ type Header struct {
ProtocolVersion string
// Bloom filter on the events emitted this block
EventsBloom *bloom.BloomFilter
// Amount of WEI charged per Gas spent
GasPrice *felt.Felt
// Amount of WEI charged per Gas spent on L1
L1GasPriceETH *felt.Felt `cbor:"gasprice"`
// Amount of STRK charged per Gas spent on L2
L2GasPriceETH *felt.Felt
AnkushinDaniil marked this conversation as resolved.
Show resolved Hide resolved
// Sequencer signatures
Signatures [][]*felt.Felt
// Amount of STRK charged per Gas spent
GasPriceSTRK *felt.Felt
// Amount of STRK charged per Gas spent on L1
L1GasPriceSTRK *felt.Felt `cbor:"gaspricestrk"`
// Amount of STRK charged per Gas spent on L2
L2GasPriceSTRK *felt.Felt
// The mode of the L1 data availability
L1DAMode L1DAMode
// The gas price for L1 data availability
Expand Down Expand Up @@ -224,8 +228,8 @@ func post0134Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments

pricesHash := gasPricesHash(
GasPrice{
PriceInFri: b.GasPriceSTRK,
PriceInWei: b.GasPrice,
PriceInFri: b.L1GasPriceSTRK,
PriceInWei: b.L1GasPriceETH,
},
*b.L1DataGasPrice,
*b.L2GasPrice,
Expand Down Expand Up @@ -297,11 +301,11 @@ func post0132Hash(b *Block, stateDiff *StateDiff) (*felt.Felt, *BlockCommitments
new(felt.Felt).SetUint64(b.Timestamp), // block timestamp
concatCounts,
sdCommitment,
txCommitment, // transaction commitment
eCommitment, // event commitment
rCommitment, // receipt commitment
b.GasPrice, // gas price in wei
b.GasPriceSTRK, // gas price in fri
txCommitment, // transaction commitment
eCommitment, // event commitment
rCommitment, // receipt commitment
b.L1GasPriceETH, // gas price in wei
b.L1GasPriceSTRK, // gas price in fri
b.L1DataGasPrice.PriceInWei,
b.L1DataGasPrice.PriceInFri,
new(felt.Felt).SetBytes([]byte(b.ProtocolVersion)),
Expand Down
1 change: 1 addition & 0 deletions core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type GasConsumed struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
}

type TransactionReceipt struct {
Expand Down
1 change: 1 addition & 0 deletions core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type ExecutionResources struct {
type DataAvailability struct {
L1Gas uint64
L1DataGas uint64
L2Gas uint64
}

type BuiltinInstanceCounter struct {
Expand Down
2 changes: 1 addition & 1 deletion p2p/gen/class.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/gen/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion p2p/gen/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading