Skip to content

Commit f148204

Browse files
committed
fix: machine behavior in cases of input reject or exception
1 parent aadf4f9 commit f148204

4 files changed

Lines changed: 43 additions & 9 deletions

File tree

Makefile

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,39 @@ integration-test: ## Execute e2e tests
196196
@echo "Running end-to-end tests"
197197
@go test -count=1 ./test --tags=endtoendtests
198198

199-
echo-dapp: applications/echo-dapp ## Echo the dapp
199+
echo-dapp: applications/echo-dapp ## Echo dapp
200+
201+
reject-dapp: applications/reject-dapp ## Reject dapp
202+
203+
exception-dapp: applications/exception-dapp ## Exception dapp
200204

201205
applications/echo-dapp: ## Create echo-dapp test application
202206
@echo "Creating echo-dapp test application"
203207
@mkdir -p applications
204208
@cartesi-machine --ram-length=128Mi --store=applications/echo-dapp --final-hash -- ioctl-echo-loop --vouchers=1 --delegate-call-vouchers=1 --notices=1 --reports=1 --verbose=1
205209

210+
applications/reject-dapp: ## Create reject-dapp test application
211+
@echo "Creating reject-dapp test application"
212+
@mkdir -p applications
213+
@cartesi-machine --ram-length=128Mi --store=applications/reject-dapp --final-hash -- "rollup accept && rollup reject"
214+
215+
applications/exception-dapp: ## Create exception-dapp test application
216+
@echo "Creating exception-dapp test application"
217+
@mkdir -p applications
218+
@cartesi-machine --ram-length=128Mi --store=applications/exception-dapp --final-hash -- "rollup accept && echo '{\"payload\": \"0x7468697320697320612064756d6d7920657863657074696f6e2074657874\"}' | rollup exception"
219+
206220
deploy-echo-dapp: applications/echo-dapp ## Deploy echo-dapp test application
207221
@echo "Deploying echo-dapp test application"
208222
@./cartesi-rollups-cli deploy application echo-dapp applications/echo-dapp/
209223

224+
deploy-reject-dapp: applications/reject-dapp ## Deploy reject-dapp test application
225+
@echo "Deploying reject-dapp test application"
226+
@./cartesi-rollups-cli deploy application reject-dapp applications/reject-dapp/
227+
228+
deploy-exception-dapp: applications/exception-dapp ## Deploy exception-dapp test application
229+
@echo "Deploying exception-dapp test application"
230+
@./cartesi-rollups-cli deploy application exception-dapp applications/exception-dapp/
231+
210232
# Temporary test dependencies target while we are not using distribution packages
211233
DOWNLOADS_DIR = test/downloads
212234
CARTESI_TEST_MACHINE_IMAGES = $(DOWNLOADS_DIR)/linux.bin

internal/advancer/advancer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ func (s *Service) processInputs(ctx context.Context, app *Application, inputs []
236236
return err
237237
}
238238

239+
s.Logger.Info("Processing input finished",
240+
"application", app.Name,
241+
"epoch", input.EpochIndex,
242+
"index", input.Index,
243+
"status", result.Status,
244+
"outputs", len(result.Outputs),
245+
"reports", len(result.Reports),
246+
)
247+
239248
// Store the result in the database
240249
err = s.repository.StoreAdvanceResult(ctx, input.EpochApplicationID, result)
241250
if err != nil {

pkg/machine/implementation.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,21 @@ func (m *machineImpl) OutputsHash(ctx context.Context) (Hash, error) {
128128

129129
// Advance sends an input to the machine and processes it
130130
func (m *machineImpl) Advance(ctx context.Context, input []byte) (bool, []Output, []Report, Hash, error) {
131+
outputsHash := Hash{}
132+
131133
// TODO: return the exception reason
132134
accepted, outputs, reports, data, err := m.process(ctx, input, AdvanceStateRequest)
133135
if err != nil {
134-
return accepted, outputs, reports, Hash{}, err
136+
return accepted, outputs, reports, outputsHash, err
135137
}
136138

137-
if length := len(data); length != HashSize {
138-
err = fmt.Errorf("%w (it has %d bytes)", ErrHashLength, length)
139-
return accepted, outputs, reports, Hash{}, err
139+
if accepted {
140+
if length := len(data); length != HashSize {
141+
err = fmt.Errorf("%w (it has %d bytes)", ErrHashLength, length)
142+
return accepted, outputs, reports, outputsHash, err
143+
}
144+
copy(outputsHash[:], data)
140145
}
141-
142-
var outputsHash Hash
143-
copy(outputsHash[:], data)
144146
return accepted, outputs, reports, outputsHash, nil
145147
}
146148

pkg/machine/implementation_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (s *ImplementationSuite) TestAdvance() {
266266
require.False(accepted)
267267
require.Empty(outputs)
268268
require.Empty(reports)
269-
require.NotEqual(Hash{}, hash)
269+
require.Equal(Hash{}, hash)
270270
mockBackend2.AssertExpectations(s.T())
271271

272272
// Test advance with exception
@@ -286,6 +286,7 @@ func (s *ImplementationSuite) TestAdvance() {
286286
accepted, outputs, reports, hash, err = machine3.Advance(ctx, input)
287287
require.ErrorIs(err, ErrException)
288288
require.False(accepted)
289+
require.Equal(Hash{}, hash)
289290
mockBackend3.AssertExpectations(s.T())
290291

291292
// Test advance with payload too large

0 commit comments

Comments
 (0)