Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NethermindEth/juno
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8dec96e9f50c5c5769dcdb28ca63f64fe3af9825
Choose a base ref
..
head repository: NethermindEth/juno
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8ce0d16312cb40fa82cae5429fb7a52d2a5b0fc5
Choose a head ref
Showing with 6,913 additions and 3,418 deletions.
  1. +2 −0 .golangci.yaml
  2. +1 −1 Makefile
  3. +23 −6 adapters/core2p2p/block.go
  4. +11 −6 adapters/core2p2p/receipt.go
  5. +36 −0 adapters/core2p2p/receipt_pkg_test.go
  6. +3 −2 adapters/core2p2p/transaction.go
  7. +8 −5 adapters/p2p2core/block.go
  8. +4 −2 adapters/p2p2core/receipt.go
  9. +47 −0 adapters/p2p2core/receipt_test.go
  10. +0 −1 adapters/p2p2core/state.go
  11. +9 −6 adapters/p2p2core/transaction.go
  12. +3 −2 adapters/sn2core/sn2core.go
  13. +38 −13 adapters/sn2core/sn2core_test.go
  14. +6 −6 clients/feeder/feeder_test.go
  15. +0 −1,670 clients/feeder/testdata/sepolia/block/284801.json
  16. +246 −0 clients/feeder/testdata/sepolia/block/469719.json
  17. +0 −1 clients/feeder/testdata/sepolia/signature/284801.json
  18. +1 −0 clients/feeder/testdata/sepolia/signature/469719.json
  19. +8 −8 ...16b0b6f3b1f74176d4.json → 0x304c78cccf0569159d4b2aff2117f060509b7c6d590ae740d2031d1eb507b10.json}
  20. +44 −25 core/block.go
  21. +1 −0 core/receipt.go
  22. 0 core/{receipt_pkg_test.go → receipt_test.go}
  23. +34 −14 core/state.go
  24. +15 −0 core/state_snapshot.go
  25. +2 −2 core/state_test.go
  26. +2 −17 core/transaction.go
  27. +884 −0 core/trie/bitarray.go
  28. +2,091 −0 core/trie/bitarray_test.go
  29. +0 −187 core/trie/key.go
  30. +0 −229 core/trie/key_test.go
  31. +20 −17 core/trie/node.go
  32. +1 −1 core/trie/node_test.go
  33. +46 −67 core/trie/proof.go
  34. +1 −1 core/trie/proof_test.go
  35. +11 −11 core/trie/storage.go
  36. +3 −3 core/trie/storage_test.go
  37. +60 −46 core/trie/trie.go
  38. +16 −17 core/trie/trie_pkg_test.go
  39. +75 −1 core/trie/trie_test.go
  40. +27 −0 core/version.go
  41. +4 −0 db/buckets.go
  42. +20 −19 go.mod
  43. +40 −40 go.sum
  44. +63 −0 mempool/db_utils.go
  45. +302 −0 mempool/mempool.go
  46. +226 −0 mempool/mempool_test.go
  47. +7 −9 migration/migration.go
  48. +5 −5 migration/migration_pkg_test.go
  49. +57 −56 mocks/mock_blockchain.go
  50. +46 −0 mocks/mock_state.go
  51. +1 −1 p2p/gen/class.pb.go
  52. +1 −1 p2p/gen/common.pb.go
  53. +1 −1 p2p/gen/event.pb.go
  54. +102 −77 p2p/gen/header.pb.go
  55. +120 −96 p2p/gen/receipt.pb.go
  56. +1 −1 p2p/gen/state.pb.go
  57. +388 −372 p2p/gen/transaction.pb.go
  58. +23 −0 p2p/hashstorage/hash_storage.go
  59. BIN p2p/hashstorage/sepolia_block_hashes.bin
  60. +19 −2 p2p/peers/handlers.go
  61. +8 −6 p2p/spec/header.proto
  62. +2 −0 p2p/spec/receipt.proto
  63. +4 −1 p2p/spec/transaction.proto
  64. +4 −2 p2p/sync/client.go
  65. +29 −7 p2p/sync/sync.go
  66. +17 −2 rpc/block.go
  67. +6 −0 rpc/block_test.go
  68. +0 −62 rpc/contract.go
  69. +0 −174 rpc/contract_test.go
  70. +50 −6 rpc/estimate_fee.go
  71. +43 −0 rpc/estimate_fee_pkg_test.go
  72. +21 −3 rpc/estimate_fee_test.go
  73. +13 −2 rpc/handlers.go
  74. +1 −1 rpc/handlers_test.go
  75. +9 −4 rpc/helpers.go
  76. +5 −0 rpc/init_test.go
  77. +7 −7 rpc/l1_test.go
  78. +32 −32 rpc/simulation.go
  79. +40 −0 rpc/simulation_pkg_test.go
  80. +317 −0 rpc/storage.go
  81. +766 −0 rpc/storage_test.go
  82. +24 −24 rpc/subscriptions_test.go
  83. +2 −1 rpc/trace.go
  84. +25 −11 rpc/trace_test.go
  85. +6 −0 rpc/transaction.go
  86. +35 −7 rpc/transaction_test.go
  87. +3 −3 starknet/block.go
  88. +1 −1 starknet/compiler/rust/Cargo.toml
  89. +2 −0 starknet/transaction.go
  90. +13 −0 sync/pending.go
  91. +3 −2 sync/sync.go
  92. +12 −0 utils/orderedset.go
  93. +142 −0 utils/orderedset_test.go
  94. +26 −5 utils/slices.go
  95. +32 −0 utils/slices_test.go
  96. +3 −3 vm/vm.go
  97. +5 −5 vm/vm_test.go
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -110,6 +110,8 @@ linters:
- tparallel
- gci
- exhaustruct
- usetesting
- nilnesserr

# don't enable:
# - asciicheck
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 23 additions & 6 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
@@ -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]),
@@ -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),
@@ -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),
}
}

17 changes: 11 additions & 6 deletions adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
@@ -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("")
}

@@ -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{
@@ -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
@@ -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]),
}
}

13 changes: 8 additions & 5 deletions adapters/p2p2core/block.go
Original file line number Diff line number Diff line change
@@ -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
}
}

6 changes: 4 additions & 2 deletions adapters/p2p2core/receipt.go
Original file line number Diff line number Diff line change
@@ -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(),
}
}
@@ -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),
},
}
}
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
@@ -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,
15 changes: 9 additions & 6 deletions adapters/p2p2core/transaction.go
Original file line number Diff line number Diff line change
@@ -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),
@@ -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,
@@ -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,
5 changes: 3 additions & 2 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
@@ -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),
@@ -88,6 +88,7 @@ func adaptGasConsumed(response *starknet.GasConsumed) *core.GasConsumed {
return &core.GasConsumed{
L1Gas: response.L1Gas,
L1DataGas: response.L1DataGas,
L2Gas: response.L2Gas,
}
}

Loading