Skip to content

Commit

Permalink
PLAT-671: send VDelegatedRequestFinished after retries for correct pe…
Browse files Browse the repository at this point in the history
…nding count (#568)

add send, add log in handler for empty latestState case, actualize test
  • Loading branch information
aalekseev-ru authored Jul 24, 2020
1 parent 02d09c5 commit 7364d10
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 9 additions & 2 deletions ledger-core/virtual/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ func (s *SMExecute) stepSendOutgoing(ctx smachine.ExecutionContext) smachine.Sta
}
} else {
if s.outgoingSentCounter >= MaxOutgoingSendCount {
// TODO when CallSummary will live longer than one pulse it needs to be updated
s.sendDelegatedRequestFinished(ctx, nil)
return ctx.Error(throw.E("outgoing retries limit"))
}

Expand Down Expand Up @@ -927,6 +929,12 @@ func (s *SMExecute) stepSendDelegatedRequestFinished(ctx smachine.ExecutionConte
}
}

s.sendDelegatedRequestFinished(ctx, lastState)

return ctx.Stop()
}

func (s *SMExecute) sendDelegatedRequestFinished(ctx smachine.ExecutionContext, lastState *payload.ObjectState) {
msg := payload.VDelegatedRequestFinished{
CallType: s.Payload.CallType,
CallFlags: s.Payload.CallFlags,
Expand All @@ -945,10 +953,9 @@ func (s *SMExecute) stepSendDelegatedRequestFinished(ctx smachine.ExecutionConte
}
}
}).WithoutAutoWakeUp().Start()

return ctx.Stop()
}


func (s *SMExecute) makeNewDescriptor(class reference.Global, memory []byte) descriptor.Object {
var prevStateIDBytes []byte
objDescriptor := s.execution.ObjectDescriptor
Expand Down
1 change: 0 additions & 1 deletion ledger-core/virtual/execute/execute.plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ state "stepSendDelegatedRequestFinished" as T01_S031
T01_S031 : SMExecute
T01_S031 --[dotted]> T01_S016
T01_S031 --[dotted]> T01_S001
T01_S031 --> T01_S011 : PrepareAsync(ctx).WithoutAutoWakeUp()
T01_S031 --> [*]
state "stepSendOutgoing" as T01_S025
T01_S025 : SMExecute
Expand Down
15 changes: 15 additions & 0 deletions ledger-core/virtual/handlers/vdelegatedrequestfinished.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ type unexpectedVDelegateRequestFinished struct {
Ordered bool
}

type noLatestStateTolerableVDelegateRequestFinished struct {
*log.Msg `txt:"Tolerable VDelegateRequestFinished on Empty object has no LatestState"`
Object reference.Holder
Request reference.Holder
}

var dSMVDelegatedRequestFinishedInstance smachine.StateMachineDeclaration = &dSMVDelegatedRequestFinished{}

type dSMVDelegatedRequestFinished struct {
Expand Down Expand Up @@ -154,6 +160,15 @@ func (s *SMVDelegatedRequestFinished) updateSharedState(
if s.hasLatestState() {
state.SetDescriptorDirty(s.latestState())
s.updateObjectState(state)
} else if s.Payload.CallFlags.GetInterference() == contract.CallTolerable &&
s.Payload.CallType == payload.CTConstructor &&
state.GetState() == object.Empty {

ctx.Log().Warn(noLatestStateTolerableVDelegateRequestFinished{
Object: objectRef,
Request: requestRef,
})
state.SetState(object.Missing)
}

pendingList := state.PendingTable.GetList(s.Payload.CallFlags.GetInterference())
Expand Down
4 changes: 4 additions & 0 deletions ledger-core/virtual/integration/contract_calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,8 @@ func TestVirtual_CallContractFromContract_RetryLimit(t *testing.T) {
return false
})

typedChecker.VDelegatedRequestFinished.Set(func(finished *payload.VDelegatedRequestFinished) bool { return false })

}

server.WaitIdleConveyor()
Expand All @@ -776,6 +778,8 @@ func TestVirtual_CallContractFromContract_RetryLimit(t *testing.T) {
testutils.WaitSignalsTimed(t, 10*time.Second, server.Journal.WaitAllAsyncCallsDone(), executeStopped, foundError)

require.Equal(t, countChangePulse, typedChecker.VCallRequest.Count())
require.Equal(t, countChangePulse, typedChecker.VDelegatedCallRequest.Count())
require.Equal(t, 1, typedChecker.VDelegatedRequestFinished.Count())

mc.Finish()

Expand Down

0 comments on commit 7364d10

Please sign in to comment.