Skip to content

Commit ffdb3cb

Browse files
authored
fix: update tendermint tests and validator logic (#2895)
* fix: update Tendermint tests and validator logic
1 parent 689007a commit ffdb3cb

File tree

3 files changed

+19
-59
lines changed

3 files changed

+19
-59
lines changed

builder/builder.go

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -302,34 +302,19 @@ func (b *Builder) ProposalInit(pInit *types.ProposalInit) error {
302302
ProtocolVersion: blockchain.SupportedStarknetVersion.String(),
303303
// Todo: once the spec is finalised, handle these fields (if they still exist)
304304
// OldStateRoot, VersionConstantCommitment, NextL2GasPriceFRI
305-
L1GasPriceETH: header.L1GasPriceETH,
305+
// Note: we use the header values by default, since the proposer only
306+
// sends over a subset of the gas prices (eg for L1DataGasPrice it
307+
// only sends the L1DataGasPriceWEI, but not the price in FRI, but
308+
// we need both for the block hash)
309+
L1GasPriceETH: header.L1GasPriceETH,
310+
L1GasPriceSTRK: header.L1GasPriceSTRK,
311+
L1DataGasPrice: header.L1DataGasPrice,
312+
L2GasPrice: header.L2GasPrice,
306313
},
307314
Transactions: []core.Transaction{},
308315
Receipts: []*core.TransactionReceipt{},
309316
}
310317

311-
// Old blocks do not have these values, but we need them
312-
// when we transition to a new block hash function
313-
if pendingBlock.L1GasPriceSTRK == nil {
314-
pendingBlock.L1GasPriceSTRK = new(felt.Felt).SetUint64(1)
315-
}
316-
if pendingBlock.L1GasPriceETH == nil {
317-
pendingBlock.L1GasPriceETH = new(felt.Felt).SetUint64(1)
318-
}
319-
320-
if pendingBlock.L1DataGasPrice == nil {
321-
pendingBlock.L1DataGasPrice = &core.GasPrice{
322-
PriceInWei: new(felt.Felt).SetUint64(1),
323-
PriceInFri: new(felt.Felt).SetUint64(1),
324-
}
325-
}
326-
if pendingBlock.L2GasPrice == nil {
327-
pendingBlock.L2GasPrice = &core.GasPrice{
328-
PriceInWei: new(felt.Felt).SetUint64(1),
329-
PriceInFri: new(felt.Felt).SetUint64(1),
330-
}
331-
}
332-
333318
newClasses := make(map[felt.Felt]core.Class)
334319
emptyStateDiff := core.EmptyStateDiff()
335320
su := core.StateUpdate{
@@ -350,9 +335,9 @@ func (b *Builder) SetBlockInfo(blockInfo *types.BlockInfo) {
350335
pending.Block.Header.Number = blockInfo.BlockNumber
351336
pending.Block.Header.SequencerAddress = &blockInfo.Builder
352337
pending.Block.Header.Timestamp = blockInfo.Timestamp
353-
pending.Block.Header.L2GasPrice = &core.GasPrice{PriceInFri: &blockInfo.L2GasPriceFRI}
338+
pending.Block.Header.L2GasPrice.PriceInFri = &blockInfo.L2GasPriceFRI
354339
pending.Block.Header.L1GasPriceETH = &blockInfo.L1GasPriceWEI
355-
pending.Block.Header.L1DataGasPrice = &core.GasPrice{PriceInWei: &blockInfo.L1DataGasPriceWEI}
340+
pending.Block.Header.L1DataGasPrice.PriceInWei = &blockInfo.L1DataGasPriceWEI
356341
pending.Block.Header.L1DAMode = blockInfo.L1DAMode
357342
b.pendingBlock.Store(pending)
358343
}

consensus/tendermint/tendermint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type Application[V types.Hashable[H], H types.Hash] interface {
12-
// Value returns the value to the Tendermint consensus algorith which can be proposed to other validators.
12+
// Value returns the value to the Tendermint consensus algorithm which can be proposed to other validators.
1313
Value() V
1414

1515
// Valid returns true if the provided value is valid according to the application context.

consensus/validator/validator_test.go

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/Masterminds/semver/v3"
1010
"github.com/NethermindEth/juno/blockchain"
1111
"github.com/NethermindEth/juno/builder"
12-
"github.com/NethermindEth/juno/clients/feeder"
1312
"github.com/NethermindEth/juno/consensus/types"
1413
"github.com/NethermindEth/juno/core"
1514
"github.com/NethermindEth/juno/core/felt"
@@ -18,11 +17,9 @@ import (
1817
"github.com/NethermindEth/juno/mempool"
1918
rpc "github.com/NethermindEth/juno/rpc/v8"
2019
"github.com/NethermindEth/juno/sequencer"
21-
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
2220
"github.com/NethermindEth/juno/utils"
2321
"github.com/NethermindEth/juno/vm"
2422
"github.com/consensys/gnark-crypto/ecc/stark-curve/ecdsa"
25-
"github.com/stretchr/testify/assert"
2623
"github.com/stretchr/testify/require"
2724
)
2825

@@ -32,14 +29,12 @@ func (v value) Hash() felt.Felt {
3229
return *new(felt.Felt).SetUint64(uint64(v))
3330
}
3431

35-
var emptyCommitments = core.BlockCommitments{}
36-
3732
// We use a custom chain to test the consensus logic.
3833
// The reason is that our current blockifier version is incompatible
3934
// with early mainnet/sepolia blocks. And we can't execute blocks at the chain
4035
// head without access to the state. To get around this, a custom chain was used
4136
// in these tests.
42-
func getCustomBC(t *testing.T, seqAddr *felt.Felt) (*builder.Builder, *core.Header) {
37+
func getCustomBC(t *testing.T, seqAddr *felt.Felt) (*builder.Builder, *blockchain.Blockchain, *core.Header) {
4338
t.Helper()
4439

4540
// transfer tokens to 0x101
@@ -96,32 +91,14 @@ func getCustomBC(t *testing.T, seqAddr *felt.Felt) (*builder.Builder, *core.Head
9691
}
9792
head, err := seq.RunOnce()
9893
require.NoError(t, err)
99-
return &testBuilder, head
100-
}
101-
102-
// getBlockchain returns the blockchain at network, where block 0 has been stored.
103-
func getBlockchain(t *testing.T, network *utils.Network) (*blockchain.Blockchain, *memory.Database) {
104-
client := feeder.NewTestClient(t, network)
105-
gw := adaptfeeder.New(client)
106-
107-
block0, err := gw.BlockByNumber(t.Context(), 0)
108-
require.NoError(t, err)
109-
110-
stateUpdate0, err := gw.StateUpdate(t.Context(), 0)
111-
require.NoError(t, err)
112-
113-
testDB := memory.New()
114-
chain := blockchain.New(testDB, network)
115-
assert.NoError(t, chain.Store(block0, &emptyCommitments, stateUpdate0, nil))
116-
117-
return chain, testDB
94+
return &testBuilder, bc, head
11895
}
11996

12097
// This test assumes Sepolia block 0 has been committed, and now
12198
// the Proposer proposes an empty block for block 1
12299
func TestEmptyProposal(t *testing.T) {
123100
proposerAddr := utils.HexToFelt(t, "0xabcdef")
124-
chain, _ := getBlockchain(t, &utils.Sepolia)
101+
_, chain, head := getCustomBC(t, proposerAddr)
125102
log := utils.NewNopZapLogger()
126103
vm := vm.New(false, log)
127104
testBuilder := builder.New(chain, vm, log, false)
@@ -130,16 +107,14 @@ func TestEmptyProposal(t *testing.T) {
130107

131108
// Step 1: ProposalInit
132109
proposalInit := types.ProposalInit{
133-
BlockNum: 1,
110+
BlockNum: head.Number + 1,
134111
Proposer: *proposerAddr,
135112
}
136113
require.NoError(t, validator.ProposalInit(&proposalInit))
137114

138-
block0, err := chain.BlockByNumber(0)
139-
require.NoError(t, err)
140115
emptyCommitment := types.ProposalCommitment{
141-
BlockNumber: 1,
142-
ParentCommitment: *block0.Hash,
116+
BlockNumber: head.Number + 1,
117+
ParentCommitment: *head.Hash,
143118
Builder: *proposerAddr,
144119
Timestamp: 0,
145120
ProtocolVersion: *blockchain.SupportedStarknetVersion,
@@ -151,7 +126,7 @@ func TestEmptyProposal(t *testing.T) {
151126
// Step 3: ProposalFin
152127
// Note: this commitment depends on the SupportedStarknetVersion, so block1Hash test should be updated whenever
153128
// we update SupportedStarknetVersion
154-
block1Hash, err := new(felt.Felt).SetString("0x10ccfbbc0b45b229f251b3f058bae326f7c4475fc9e7de802ce29ccea55e68b")
129+
block1Hash, err := new(felt.Felt).SetString("0x27a852d180c77e0b7bc2b3e9b635b625db3ae48f2c469c93930c1889ae2d09f")
155130
require.NoError(t, err)
156131
proposalFin := types.ProposalFin(*block1Hash)
157132
require.NoError(t, validator.ProposalFin(proposalFin))
@@ -162,7 +137,7 @@ func TestEmptyProposal(t *testing.T) {
162137
// The validator should re-execute it, and come to agreement on the resulting commitments.
163138
func TestProposal(t *testing.T) {
164139
proposerAddr := utils.HexToFelt(t, "0xDEADBEEF")
165-
builder, head := getCustomBC(t, proposerAddr)
140+
builder, _, head := getCustomBC(t, proposerAddr)
166141
validator := New[value, felt.Felt, felt.Felt](builder)
167142

168143
// Step 1: ProposalInit

0 commit comments

Comments
 (0)