Skip to content

Commit

Permalink
Merge branch 'main' into feature/sequencer-genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Jan 23, 2025
2 parents 924d2dc + 21f442f commit 41bd928
Show file tree
Hide file tree
Showing 85 changed files with 5,071 additions and 3,195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/starknet-go-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
run: go mod download

- name: Test RPC on testnet
run: cd rpc && go test -timeout 1200s -v -env testnet .
run: cd rpc && go test -skip 'TestBlockWithReceipts' -timeout 1200s -v -env testnet .
env:
INTEGRATION_BASE: ${{ secrets.TEST_RPC_URL }}
2 changes: 1 addition & 1 deletion .github/workflows/starknet-rs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Run jsonrpc tests
run: |
cd starknet-providers && cargo test jsonrpc
cd ../starknet-accounts && cargo test jsonrpc -- --skip can_declare_cairo0_contract_with_jsonrpc
cd ../starknet-accounts && cargo test jsonrpc -- --skip can_declare_cairo0_contract_with_jsonrpc --skip jsonrpc_get_block_with_receipts
env:
STARKNET_RPC: ${{ secrets.STARKNET_RPC }}
RUST_BACKTRACE: full
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ linters:
- tparallel
- gci
- exhaustruct
- usetesting
- nilnesserr

# don't enable:
# - asciicheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ install-mockgen:
go install go.uber.org/mock/mockgen@latest

install-golangci-lint:
@which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
@which golangci-lint || go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4

lint: install-golangci-lint ## Run linter
golangci-lint run
Expand Down
29 changes: 23 additions & 6 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func AdaptBlockID(header *core.Header) *gen.BlockID {
}
}

func AdaptSignature(sig []*felt.Felt) *gen.ConsensusSignature {
func adaptSignature(sig []*felt.Felt) *gen.ConsensusSignature {
return &gen.ConsensusSignature{
R: AdaptFelt(sig[0]),
S: AdaptFelt(sig[1]),
Expand All @@ -30,6 +30,21 @@ func AdaptSignature(sig []*felt.Felt) *gen.ConsensusSignature {
func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
stateDiffCommitment *felt.Felt, stateDiffLength uint64,
) *gen.SignedBlockHeader {
var l1DataGasPriceFri, l1DataGasPriceWei, l2GasPriceFri, l2GasPriceWei *felt.Felt
if l1DataGasPrice := header.L1DataGasPrice; l1DataGasPrice != nil {
l1DataGasPriceFri = l1DataGasPrice.PriceInFri
l1DataGasPriceWei = l1DataGasPrice.PriceInWei
} else {
l1DataGasPriceFri = &felt.Zero
l1DataGasPriceWei = &felt.Zero
}
if l2GasPrice := header.L2GasPrice; l2GasPrice != nil {
l2GasPriceFri = l2GasPrice.PriceInFri
l2GasPriceWei = l2GasPrice.PriceInWei
} else {
l2GasPriceFri = &felt.Zero
l2GasPriceWei = &felt.Zero
}
return &gen.SignedBlockHeader{
BlockHash: AdaptHash(header.Hash),
ParentHash: AdaptHash(header.ParentHash),
Expand All @@ -47,16 +62,18 @@ func AdaptHeader(header *core.Header, commitments *core.BlockCommitments,
},
Receipts: AdaptHash(commitments.ReceiptCommitment),
ProtocolVersion: header.ProtocolVersion,
GasPriceFri: AdaptUint128(header.GasPriceSTRK),
Signatures: utils.Map(header.Signatures, AdaptSignature),
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(l1DataGasPriceFri),
L1DataGasPriceWei: AdaptUint128(l1DataGasPriceWei),
L1DataAvailabilityMode: adaptL1DA(header.L1DAMode),
L2GasPriceFri: AdaptUint128(l2GasPriceFri),
L2GasPriceWei: AdaptUint128(l2GasPriceWei),
}
}

Expand Down
17 changes: 11 additions & 6 deletions adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func receiptCommon(r *core.TransactionReceipt) *gen.Receipt_Common {
if r.RevertReason != "" {
revertReason = &r.RevertReason
} else if r.Reverted {
// in some cases receipt marked as reverted may contain empty string in revert_reason
revertReason = utils.Ptr("")
}

Expand Down Expand Up @@ -103,13 +104,15 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
return nil
}

var l1Gas, l1DataGas, totalL1Gas *felt.Felt
var l1Gas, l1DataGas, l2Gas, totalL1Gas, totalL1DataGas *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 {
totalL1Gas = new(felt.Felt).SetUint64(tgs.L1Gas)
totalL1DataGas = new(felt.Felt).SetUint64(tgs.L1DataGas)
}

return &gen.Receipt_ExecutionResources{
Expand All @@ -126,10 +129,12 @@ func AdaptExecutionResources(er *core.ExecutionResources) *gen.Receipt_Execution
MulMod: uint32(er.BuiltinInstanceCounter.MulMod),
RangeCheck96: uint32(er.BuiltinInstanceCounter.RangeCheck96),
},
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
L1Gas: AdaptFelt(l1Gas),
L1DataGas: AdaptFelt(l1DataGas),
TotalL1Gas: AdaptFelt(totalL1Gas),
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
L1Gas: AdaptFelt(l1Gas),
L1DataGas: AdaptFelt(l1DataGas),
TotalL1Gas: AdaptFelt(totalL1Gas),
TotalL1DataGas: AdaptFelt(totalL1DataGas),
L2Gas: AdaptFelt(l2Gas),
}
}
36 changes: 36 additions & 0 deletions adapters/core2p2p/receipt_pkg_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package core2p2p

import (
"testing"

"github.com/NethermindEth/juno/core"
"github.com/stretchr/testify/assert"
)

func TestReceiptCommon(t *testing.T) {
t.Run("successful", func(t *testing.T) {
receipt := &core.TransactionReceipt{
Reverted: false,
}
r := receiptCommon(receipt)
// if RevertReason is nil then receipt considered as non reverted
assert.Nil(t, r.RevertReason)
})
t.Run("reverted", func(t *testing.T) {
receipts := []*core.TransactionReceipt{
{
Reverted: true,
RevertReason: "Reason",
},
{
Reverted: true,
RevertReason: "",
},
}

for _, receipt := range receipts {
r := receiptCommon(receipt)
assert.Equal(t, &receipt.RevertReason, r.RevertReason)
}
})
}
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
13 changes: 8 additions & 5 deletions adapters/p2p2core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ func AdaptBlockHeader(h *gen.SignedBlockHeader, eventsBloom *bloom.BloomFilter)
Timestamp: h.Time,
ProtocolVersion: h.ProtocolVersion,
EventsBloom: eventsBloom,
L1GasPriceETH: AdaptUint128(h.L1GasPriceWei),
Signatures: utils.Map(h.Signatures, adaptSignature),
L1GasPriceSTRK: AdaptUint128(h.L1GasPriceFri),
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
6 changes: 4 additions & 2 deletions adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func AdaptReceipt(r *gen.Receipt, txHash *felt.Felt) *core.TransactionReceipt {
L1ToL2Message: nil,
L2ToL1Message: utils.Map(common.MessagesSent, adaptMessageToL1),
TransactionHash: txHash,
Reverted: common.RevertReason != nil, // todo is it correct?
Reverted: common.RevertReason != nil, // in case it's empty string we should treat it as reverted
RevertReason: common.GetRevertReason(),
}
}
Expand All @@ -58,14 +58,16 @@ 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),
L1DataGas: feltToUint64(er.TotalL1DataGas),
},
}
}
Expand Down
47 changes: 47 additions & 0 deletions adapters/p2p2core/receipt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package p2p2core_test

import (
"testing"

"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/p2p/gen"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
)

func TestAdaptReceipt(t *testing.T) {
t.Run("successful", func(t *testing.T) {
hash := utils.HexToFelt(t, "0xCAFEBABE")
receipt := &gen.Receipt{
Type: &gen.Receipt_L1Handler_{
L1Handler: &gen.Receipt_L1Handler{
Common: &gen.Receipt_Common{
RevertReason: nil,
},
},
},
}
r := p2p2core.AdaptReceipt(receipt, hash)
assert.False(t, r.Reverted)
assert.Equal(t, "", r.RevertReason)
})
t.Run("reverted", func(t *testing.T) {
reasons := []string{"reason", ""}

for _, reason := range reasons {
hash := utils.HexToFelt(t, "0xCAFEDEAD")
receipt := &gen.Receipt{
Type: &gen.Receipt_L1Handler_{
L1Handler: &gen.Receipt_L1Handler{
Common: &gen.Receipt_Common{
RevertReason: utils.Ptr(reason),
},
},
},
}
r := p2p2core.AdaptReceipt(receipt, hash)
assert.True(t, r.Reverted)
assert.Equal(t, receipt.GetL1Handler().GetCommon().GetRevertReason(), r.RevertReason)
}
})
}
1 change: 0 additions & 1 deletion adapters/p2p2core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func AdaptStateDiff(reader core.StateReader, contractDiffs []*gen.ContractDiff,
storageDiffs[*address] = utils.ToMap(diff.Values, adaptStoredValue)
}

// todo recheck this logic
if diff.ClassHash != nil {
addrToClsHash := addrToClassHash{
addr: diff.Address,
Expand Down
15 changes: 9 additions & 6 deletions adapters/p2p2core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ func AdaptTransaction(t *gen.Transaction, network *utils.Network) core.Transacti
CompiledClassHash: AdaptHash(tx.CompiledClassHash),
Tip: tx.Tip,
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1DataGas: adaptResourceLimits(tx.ResourceBounds.L1DataGas),
},
PaymasterData: utils.Map(tx.PaymasterData, AdaptFelt),
AccountDeploymentData: utils.Map(tx.AccountDeploymentData, AdaptFelt),
Expand Down Expand Up @@ -189,8 +190,9 @@ func AdaptTransaction(t *gen.Transaction, network *utils.Network) core.Transacti
Nonce: AdaptFelt(tx.Nonce),
Tip: tx.Tip,
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1DataGas: adaptResourceLimits(tx.ResourceBounds.L1DataGas),
},
PaymasterData: utils.Map(tx.PaymasterData, AdaptFelt),
NonceDAMode: nDAMode,
Expand Down Expand Up @@ -268,8 +270,9 @@ func AdaptTransaction(t *gen.Transaction, network *utils.Network) core.Transacti
EntryPointSelector: nil,
Tip: tx.Tip,
ResourceBounds: map[core.Resource]core.ResourceBounds{
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1Gas: adaptResourceLimits(tx.ResourceBounds.L1Gas),
core.ResourceL2Gas: adaptResourceLimits(tx.ResourceBounds.L2Gas),
core.ResourceL1DataGas: adaptResourceLimits(tx.ResourceBounds.L1DataGas),
},
PaymasterData: utils.Map(tx.PaymasterData, AdaptFelt),
NonceDAMode: nDAMode,
Expand Down
5 changes: 3 additions & 2 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ 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(),
L1GasPriceSTRK: response.L1GasPriceSTRK(),
L1DAMode: core.L1DAMode(response.L1DAMode),
L1DataGasPrice: (*core.GasPrice)(response.L1DataGasPrice),
L2GasPrice: (*core.GasPrice)(response.L2GasPrice),
Expand Down Expand Up @@ -88,6 +88,7 @@ func adaptGasConsumed(response *starknet.GasConsumed) *core.GasConsumed {
return &core.GasConsumed{
L1Gas: response.L1Gas,
L1DataGas: response.L1DataGas,
L2Gas: response.L2Gas,
}
}

Expand Down
Loading

0 comments on commit 41bd928

Please sign in to comment.