Skip to content

Commit 4f4085b

Browse files
committed
updates
1 parent 2c610be commit 4f4085b

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

block/internal/executing/executor.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ func (e *Executor) Stop() error {
154154
func (e *Executor) GetLastState() types.State {
155155
state := e.lastState.Load()
156156
if state == nil {
157-
// Return zero value if not initialized
158157
return types.State{}
159158
}
160-
return *state
159+
160+
stateCopy := *state
161+
stateCopy.AppHash = bytes.Clone(state.AppHash)
162+
stateCopy.LastResultsHash = bytes.Clone(state.LastResultsHash)
163+
164+
return stateCopy
161165
}
162166

163167
// SetLastState updates the current state

block/internal/syncing/syncer.go

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ type Syncer struct {
4747
options common.BlockOptions
4848

4949
// State management
50-
lastState types.State
51-
lastStateMtx *sync.RWMutex
50+
lastState *atomic.Pointer[types.State]
5251

5352
// DA state
5453
daHeight uint64
@@ -90,20 +89,20 @@ func NewSyncer(
9089
errorCh chan<- error,
9190
) *Syncer {
9291
return &Syncer{
93-
store: store,
94-
exec: exec,
95-
da: da,
96-
cache: cache,
97-
metrics: metrics,
98-
config: config,
99-
genesis: genesis,
100-
options: options,
101-
headerStore: headerStore,
102-
dataStore: dataStore,
103-
lastStateMtx: &sync.RWMutex{},
104-
heightInCh: make(chan common.DAHeightEvent, 10_000),
105-
errorCh: errorCh,
106-
logger: logger.With().Str("component", "syncer").Logger(),
92+
store: store,
93+
exec: exec,
94+
da: da,
95+
cache: cache,
96+
metrics: metrics,
97+
config: config,
98+
genesis: genesis,
99+
options: options,
100+
headerStore: headerStore,
101+
dataStore: dataStore,
102+
lastState: &atomic.Pointer[types.State]{},
103+
heightInCh: make(chan common.DAHeightEvent, 10_000),
104+
errorCh: errorCh,
105+
logger: logger.With().Str("component", "syncer").Logger(),
107106
}
108107
}
109108

@@ -150,16 +149,21 @@ func (s *Syncer) Stop() error {
150149

151150
// GetLastState returns the current state
152151
func (s *Syncer) GetLastState() types.State {
153-
s.lastStateMtx.RLock()
154-
defer s.lastStateMtx.RUnlock()
155-
return s.lastState
152+
state := s.lastState.Load()
153+
if state == nil {
154+
return types.State{}
155+
}
156+
157+
stateCopy := *state
158+
stateCopy.AppHash = bytes.Clone(state.AppHash)
159+
stateCopy.LastResultsHash = bytes.Clone(state.LastResultsHash)
160+
161+
return stateCopy
156162
}
157163

158164
// SetLastState updates the current state
159165
func (s *Syncer) SetLastState(state types.State) {
160-
s.lastStateMtx.Lock()
161-
defer s.lastStateMtx.Unlock()
162-
s.lastState = state
166+
s.lastState.Store(&state)
163167
}
164168

165169
// GetDAHeight returns the current DA height

scripts/test.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ test-integration-cover:
3636
## test-cover: generate code coverage report.
3737
test-cover:
3838
@echo "--> Running unit tests"
39-
@go run -tags=cover scripts/test_cover.go
39+
@go run -tags=cover -race scripts/test_cover.go
4040
.PHONY: test-cover
4141

4242
## bench: run micro-benchmarks for internal cache

0 commit comments

Comments
 (0)