Skip to content

Commit ffac7aa

Browse files
authored
Merge branch 'main' into da-interface-part3
2 parents 7eb9c59 + b3f2dfb commit ffac7aa

File tree

9 files changed

+28
-62
lines changed

9 files changed

+28
-62
lines changed

block/components.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,6 @@ type Components struct {
3535
errorCh chan error
3636
}
3737

38-
// GetLastState returns the current blockchain state
39-
func (bc *Components) GetLastState() types.State {
40-
if bc.Executor != nil {
41-
return bc.Executor.GetLastState()
42-
}
43-
if bc.Syncer != nil {
44-
return bc.Syncer.GetLastState()
45-
}
46-
return types.State{}
47-
}
48-
4938
// Start starts all components and monitors for critical errors.
5039
// It is blocking and returns when the context is cancelled or an error occurs
5140
func (bc *Components) Start(ctx context.Context) error {

block/components_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ func TestBlockComponents_ExecutionClientFailure_StopsNode(t *testing.T) {
5252
assert.Contains(t, err.Error(), "execution client connection lost")
5353
}
5454

55-
func TestBlockComponents_GetLastState(t *testing.T) {
56-
// Test that GetLastState works correctly for different component types
57-
58-
t.Run("Empty state", func(t *testing.T) {
59-
// When neither is present, return empty state
60-
bc := &Components{}
61-
62-
result := bc.GetLastState()
63-
assert.Equal(t, uint64(0), result.LastBlockHeight)
64-
})
65-
}
66-
6755
func TestBlockComponents_StartStop_Lifecycle(t *testing.T) {
6856
// Simple lifecycle test without creating full components
6957
bc := &Components{

block/internal/executing/executor.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ func (e *Executor) Stop() error {
151151
return nil
152152
}
153153

154-
// GetLastState returns the current state.
155-
func (e *Executor) GetLastState() types.State {
156-
state := e.getLastState()
157-
state.AppHash = bytes.Clone(state.AppHash)
158-
159-
return state
160-
}
161-
162154
// getLastState returns the current state.
163155
// getLastState should never directly mutate.
164156
func (e *Executor) getLastState() types.State {

block/internal/syncing/syncer.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,14 @@ func (s *Syncer) Stop() error {
226226
return nil
227227
}
228228

229-
// GetLastState returns the current state
230-
func (s *Syncer) GetLastState() types.State {
229+
// getLastState returns the current state
230+
func (s *Syncer) getLastState() types.State {
231231
state := s.lastState.Load()
232232
if state == nil {
233233
return types.State{}
234234
}
235235

236-
stateCopy := *state
237-
stateCopy.AppHash = bytes.Clone(state.AppHash)
238-
stateCopy.LastHeaderHash = bytes.Clone(state.LastHeaderHash)
239-
240-
return stateCopy
236+
return *state
241237
}
242238

243239
// SetLastState updates the current state
@@ -532,7 +528,7 @@ func (s *Syncer) processHeightEvent(event *common.DAHeightEvent) {
532528
case errors.Is(err, errInvalidState):
533529
s.sendCriticalError(fmt.Errorf("invalid state detected (block-height %d, state-height %d) "+
534530
"- block references do not match local state. Manual intervention required: %w", event.Header.Height(),
535-
s.GetLastState().LastBlockHeight, err))
531+
s.getLastState().LastBlockHeight, err))
536532
default:
537533
s.cache.SetPendingEvent(height, event)
538534
}
@@ -577,7 +573,7 @@ func (s *Syncer) trySyncNextBlock(event *common.DAHeightEvent) error {
577573
header := event.Header
578574
data := event.Data
579575
nextHeight := event.Header.Height()
580-
currentState := s.GetLastState()
576+
currentState := s.getLastState()
581577
headerHash := header.Hash().String()
582578

583579
s.logger.Info().Uint64("height", nextHeight).Msg("syncing block")

block/internal/syncing/syncer_forced_inclusion_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func TestVerifyForcedInclusionTxs_AllTransactionsIncluded(t *testing.T) {
405405
data := makeData(gen.ChainID, 1, 1)
406406
data.Txs[0] = types.Tx(dataBin)
407407

408-
currentState := s.GetLastState()
408+
currentState := s.getLastState()
409409
currentState.DAHeight = 0
410410

411411
// Verify - should pass since all forced txs are included
@@ -480,7 +480,7 @@ func TestVerifyForcedInclusionTxs_MissingTransactions(t *testing.T) {
480480
data.Txs[0] = types.Tx([]byte("regular_tx_1"))
481481
data.Txs[1] = types.Tx([]byte("regular_tx_2"))
482482

483-
currentState := s.GetLastState()
483+
currentState := s.getLastState()
484484
currentState.DAHeight = 0
485485

486486
// Verify - should pass since forced tx blob may be legitimately deferred within the epoch
@@ -584,7 +584,7 @@ func TestVerifyForcedInclusionTxs_PartiallyIncluded(t *testing.T) {
584584
data.Txs[1] = types.Tx([]byte("regular_tx"))
585585
// dataBin2 is missing
586586

587-
currentState := s.GetLastState()
587+
currentState := s.getLastState()
588588
currentState.DAHeight = 0
589589

590590
// Verify - should pass since dataBin2 may be legitimately deferred within the epoch
@@ -683,7 +683,7 @@ func TestVerifyForcedInclusionTxs_NoForcedTransactions(t *testing.T) {
683683
// Create block data
684684
data := makeData(gen.ChainID, 1, 2)
685685

686-
currentState := s.GetLastState()
686+
currentState := s.getLastState()
687687
currentState.DAHeight = 0
688688

689689
// Verify - should pass since no forced txs to verify
@@ -744,7 +744,7 @@ func TestVerifyForcedInclusionTxs_NamespaceNotConfigured(t *testing.T) {
744744
// Create block data
745745
data := makeData(gen.ChainID, 1, 2)
746746

747-
currentState := s.GetLastState()
747+
currentState := s.getLastState()
748748
currentState.DAHeight = 0
749749

750750
// Verify - should pass since namespace not configured
@@ -830,7 +830,7 @@ func TestVerifyForcedInclusionTxs_DeferralWithinEpoch(t *testing.T) {
830830
data1.Txs[0] = types.Tx(dataBin1)
831831
data1.Txs[1] = types.Tx([]byte("regular_tx_1"))
832832

833-
currentState := s.GetLastState()
833+
currentState := s.getLastState()
834834
currentState.DAHeight = 104
835835

836836
// Verify - should pass since dataBin2 can be deferred within epoch
@@ -953,7 +953,7 @@ func TestVerifyForcedInclusionTxs_MaliciousAfterEpochEnd(t *testing.T) {
953953
data1 := makeData(gen.ChainID, 1, 1)
954954
data1.Txs[0] = types.Tx([]byte("regular_tx_1"))
955955

956-
currentState := s.GetLastState()
956+
currentState := s.getLastState()
957957
currentState.DAHeight = 102
958958

959959
// Verify - should pass, tx can be deferred within epoch
@@ -1047,7 +1047,7 @@ func TestVerifyForcedInclusionTxs_SmoothingExceedsEpoch(t *testing.T) {
10471047
data1.Txs[0] = types.Tx(dataBin1)
10481048
data1.Txs[1] = types.Tx(dataBin2)
10491049

1050-
currentState := s.GetLastState()
1050+
currentState := s.getLastState()
10511051
currentState.DAHeight = 102 // At epoch end
10521052

10531053
err = s.verifyForcedInclusionTxs(currentState, data1)

block/internal/syncing/syncer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ func TestSyncer_validateBlock_DataHashMismatch(t *testing.T) {
134134
data := makeData(gen.ChainID, 1, 2) // non-empty
135135
_, header := makeSignedHeaderBytes(t, gen.ChainID, 1, addr, pub, signer, nil, data, nil)
136136

137-
err = s.validateBlock(s.GetLastState(), data, header)
137+
err = s.validateBlock(s.getLastState(), data, header)
138138
require.NoError(t, err)
139139

140140
// Create header and data with mismatched hash
141141
data = makeData(gen.ChainID, 1, 2) // non-empty
142142
_, header = makeSignedHeaderBytes(t, gen.ChainID, 1, addr, pub, signer, nil, nil, nil)
143-
err = s.validateBlock(s.GetLastState(), data, header)
143+
err = s.validateBlock(s.getLastState(), data, header)
144144
require.Error(t, err)
145145

146146
// Create header and empty data
147147
data = makeData(gen.ChainID, 1, 0) // empty
148148
_, header = makeSignedHeaderBytes(t, gen.ChainID, 2, addr, pub, signer, nil, nil, nil)
149-
err = s.validateBlock(s.GetLastState(), data, header)
149+
err = s.validateBlock(s.getLastState(), data, header)
150150
require.Error(t, err)
151151
}
152152

@@ -185,7 +185,7 @@ func TestProcessHeightEvent_SyncsAndUpdatesState(t *testing.T) {
185185
// set a context for internal loops that expect it
186186
s.ctx = context.Background()
187187
// Create signed header & data for height 1
188-
lastState := s.GetLastState()
188+
lastState := s.getLastState()
189189
data := makeData(gen.ChainID, 1, 0)
190190
_, hdr := makeSignedHeaderBytes(t, gen.ChainID, 1, addr, pub, signer, lastState.AppHash, data, nil)
191191

@@ -238,7 +238,7 @@ func TestSequentialBlockSync(t *testing.T) {
238238
s.ctx = context.Background()
239239

240240
// Sync two consecutive blocks via processHeightEvent so ExecuteTxs is called and state stored
241-
st0 := s.GetLastState()
241+
st0 := s.getLastState()
242242
data1 := makeData(gen.ChainID, 1, 1) // non-empty
243243
_, hdr1 := makeSignedHeaderBytes(t, gen.ChainID, 1, addr, pub, signer, st0.AppHash, data1, st0.LastHeaderHash)
244244
// Expect ExecuteTxs call for height 1
@@ -629,7 +629,7 @@ func TestSyncer_InitializeState_CallsReplayer(t *testing.T) {
629629
require.NoError(t, err)
630630

631631
// Verify state was initialized correctly
632-
state := syncer.GetLastState()
632+
state := syncer.getLastState()
633633
assert.Equal(t, storeHeight, state.LastBlockHeight)
634634
assert.Equal(t, gen.ChainID, state.ChainID)
635635

execution/evm/test/test_helpers.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ import (
66
"context"
77
"encoding/hex"
88
"fmt"
9-
"github.com/celestiaorg/tastora/framework/types"
10-
"github.com/golang-jwt/jwt/v5"
119
mathrand "math/rand"
1210
"net/http"
1311
"strings"
1412
"sync"
1513
"testing"
1614
"time"
1715

18-
"github.com/stretchr/testify/require"
19-
2016
"github.com/celestiaorg/tastora/framework/docker"
2117
"github.com/celestiaorg/tastora/framework/docker/evstack/reth"
18+
"github.com/celestiaorg/tastora/framework/types"
19+
"github.com/golang-jwt/jwt/v5"
20+
"github.com/stretchr/testify/require"
2221
)
2322

2423
// Test-scoped Docker client/network mapping to avoid conflicts between tests

execution/evm/test_helpers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package evm
22

33
import (
44
"context"
5+
"math/big"
6+
"math/rand"
7+
"testing"
8+
59
"github.com/ethereum/go-ethereum/common"
610
"github.com/ethereum/go-ethereum/core/types"
711
"github.com/ethereum/go-ethereum/crypto"
812
"github.com/ethereum/go-ethereum/ethclient"
913
"github.com/stretchr/testify/require"
10-
"math/big"
11-
"math/rand"
12-
"testing"
1314
)
1415

1516
// Transaction Helpers

node/single_sequencer_integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ func (s *FullNodeTestSuite) TestGenesisInitialization() {
218218
require := require.New(s.T())
219219

220220
// Verify genesis state
221-
state := s.node.blockComponents.GetLastState()
221+
state, err := s.node.Store.GetState(s.ctx)
222+
require.NoError(err)
222223
require.Equal(s.node.genesis.InitialHeight, state.InitialHeight)
223224
require.Equal(s.node.genesis.ChainID, state.ChainID)
224225
}

0 commit comments

Comments
 (0)