Skip to content

Commit 0b9557f

Browse files
authored
Merge pull request #117 from kaleido-io/pass-in-action-occurred-time
Pass in action occurred time
2 parents af4a223 + cc68a9c commit 0b9557f

19 files changed

+98
-100
lines changed

Makefile

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ test: deps lint
1616
coverage.html:
1717
$(VGO) tool cover -html=coverage.txt
1818
coverage: test coverage.html
19-
lint: ${LINT}
19+
lint:
20+
$(VGO) install github.com/golangci/golangci-lint/cmd/[email protected]
2021
GOGC=20 $(LINT) run -v --timeout 5m
2122

2223
${MOCKERY}:
2324
$(VGO) install github.com/vektra/mockery/v2@latest
24-
${LINT}:
25-
$(VGO) install github.com/golangci/golangci-lint/cmd/[email protected]
26-
2725

2826
define makemock
2927
mocks: mocks-$(strip $(1))-$(strip $(2))

internal/persistence/leveldb/leveldb_persistence.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2023 Kaleido, Inc.
1+
// Copyright © 2024 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -661,7 +661,7 @@ func (p *leveldbPersistence) DeleteTransaction(ctx context.Context, txID string)
661661
)
662662
}
663663

664-
func (p *leveldbPersistence) setSubStatusInStruct(ctx context.Context, tx *apitypes.TXWithStatus, subStatus apitypes.TxSubStatus) {
664+
func (p *leveldbPersistence) setSubStatusInStruct(ctx context.Context, tx *apitypes.TXWithStatus, subStatus apitypes.TxSubStatus, actionOccurred *fftypes.FFTime) {
665665

666666
// See if the status being transitioned to is the same as the current status.
667667
// If so, there's nothing to do.
@@ -674,7 +674,7 @@ func (p *leveldbPersistence) setSubStatusInStruct(ctx context.Context, tx *apity
674674

675675
// If this is a change in status add a new record
676676
newStatus := &apitypes.TxHistoryStateTransitionEntry{
677-
Time: fftypes.Now(),
677+
Time: actionOccurred,
678678
Status: subStatus,
679679
Actions: make([]*apitypes.TxHistoryActionEntry, 0),
680680
}
@@ -692,16 +692,16 @@ func (p *leveldbPersistence) setSubStatusInStruct(ctx context.Context, tx *apity
692692
for _, statusType := range tx.DeprecatedHistorySummary {
693693
if statusType.Status == subStatus {
694694
// Just increment the counter and last timestamp
695-
statusType.LastOccurrence = fftypes.Now()
695+
statusType.LastOccurrence = actionOccurred
696696
statusType.Count++
697697
return
698698
}
699699
}
700700

701-
tx.DeprecatedHistorySummary = append(tx.DeprecatedHistorySummary, &apitypes.TxHistorySummaryEntry{Status: subStatus, Count: 1, FirstOccurrence: fftypes.Now(), LastOccurrence: fftypes.Now()})
701+
tx.DeprecatedHistorySummary = append(tx.DeprecatedHistorySummary, &apitypes.TxHistorySummaryEntry{Status: subStatus, Count: 1, FirstOccurrence: actionOccurred, LastOccurrence: actionOccurred})
702702
}
703703

704-
func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string, subStatus apitypes.TxSubStatus, action apitypes.TxAction, info *fftypes.JSONAny, errInfo *fftypes.JSONAny) error {
704+
func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string, subStatus apitypes.TxSubStatus, action apitypes.TxAction, info *fftypes.JSONAny, errInfo *fftypes.JSONAny, actionOccurred *fftypes.FFTime) error {
705705

706706
tx, err := p.getPersistedTX(ctx, txID)
707707
if err != nil {
@@ -713,7 +713,7 @@ func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string
713713
}
714714

715715
// Ensure structure is updated to latest sub status
716-
p.setSubStatusInStruct(ctx, tx, subStatus)
716+
p.setSubStatusInStruct(ctx, tx, subStatus, actionOccurred)
717717

718718
// See if this action exists in the list already since we only want to update the single entry, not
719719
// add a new one
@@ -723,11 +723,11 @@ func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string
723723
if entry.Action == action {
724724
alreadyRecordedAction = true
725725
entry.OccurrenceCount++
726-
entry.LastOccurrence = fftypes.Now()
726+
entry.LastOccurrence = actionOccurred
727727

728728
if errInfo != nil {
729729
entry.LastError = persistence.JSONOrString(errInfo)
730-
entry.LastErrorTime = fftypes.Now()
730+
entry.LastErrorTime = actionOccurred
731731
}
732732

733733
if info != nil {
@@ -740,15 +740,15 @@ func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string
740740
if !alreadyRecordedAction {
741741
// If this is an entirely new action for this status entry, add it to the list
742742
newAction := &apitypes.TxHistoryActionEntry{
743-
Time: fftypes.Now(),
743+
Time: actionOccurred,
744744
Action: action,
745-
LastOccurrence: fftypes.Now(),
745+
LastOccurrence: actionOccurred,
746746
OccurrenceCount: 1,
747747
}
748748

749749
if errInfo != nil {
750750
newAction.LastError = persistence.JSONOrString(errInfo)
751-
newAction.LastErrorTime = fftypes.Now()
751+
newAction.LastErrorTime = actionOccurred
752752
}
753753

754754
if info != nil {
@@ -763,14 +763,14 @@ func (p *leveldbPersistence) AddSubStatusAction(ctx context.Context, txID string
763763
for _, actionType := range tx.DeprecatedHistorySummary {
764764
if actionType.Action == action {
765765
// Just increment the counter and last timestamp
766-
actionType.LastOccurrence = fftypes.Now()
766+
actionType.LastOccurrence = actionOccurred
767767
actionType.Count++
768768
found = true
769769
break
770770
}
771771
}
772772
if !found {
773-
tx.DeprecatedHistorySummary = append(tx.DeprecatedHistorySummary, &apitypes.TxHistorySummaryEntry{Action: action, Count: 1, FirstOccurrence: fftypes.Now(), LastOccurrence: fftypes.Now()})
773+
tx.DeprecatedHistorySummary = append(tx.DeprecatedHistorySummary, &apitypes.TxHistorySummaryEntry{Action: action, Count: 1, FirstOccurrence: actionOccurred, LastOccurrence: actionOccurred})
774774
}
775775
return p.writeTransaction(ctx, tx, false)
776776
}

internal/persistence/leveldb/leveldb_persistence_test.go

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2022 Kaleido, Inc.
1+
// Copyright © 2024 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -460,7 +460,7 @@ func TestAddSubStatusActionFail(t *testing.T) {
460460

461461
tx := newTestTX("0x1234", apitypes.TxStatusPending)
462462

463-
err := p.AddSubStatusAction(ctx, tx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil)
463+
err := p.AddSubStatusAction(ctx, tx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
464464
assert.Error(t, err)
465465

466466
}
@@ -834,7 +834,7 @@ func TestManagedTXSubStatus(t *testing.T) {
834834
// Adding the same sub-status lots of times in succession should only result
835835
// in a single entry for that instance
836836
for i := 0; i < 100; i++ {
837-
err := p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil)
837+
err := p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
838838
assert.NoError(t, err)
839839
}
840840

@@ -845,7 +845,7 @@ func TestManagedTXSubStatus(t *testing.T) {
845845

846846
// Adding a different type of sub-status should result in
847847
// a new entry in the list
848-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil)
848+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
849849
assert.NoError(t, err)
850850

851851
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
@@ -855,9 +855,9 @@ func TestManagedTXSubStatus(t *testing.T) {
855855
// Even if many new types are added we shouldn't go over the
856856
// configured upper limit
857857
for i := 0; i < 100; i++ {
858-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusStale, apitypes.TxActionAssignNonce, nil, nil)
858+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusStale, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
859859
assert.NoError(t, err)
860-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil)
860+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
861861
assert.NoError(t, err)
862862
}
863863

@@ -875,22 +875,22 @@ func TestManagedTXSubStatusRepeat(t *testing.T) {
875875
assert.NoError(t, err)
876876

877877
// Add a sub-status
878-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil)
878+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
879879
assert.NoError(t, err)
880880
txh, err := p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
881881
assert.NoError(t, err)
882882
assert.Equal(t, 1, len(txh.History))
883883
assert.Equal(t, 2, len(txh.DeprecatedHistorySummary))
884884

885885
// Add another sub-status
886-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionSubmitTransaction, nil, nil)
886+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusTracking, apitypes.TxActionSubmitTransaction, nil, nil, fftypes.Now())
887887
assert.NoError(t, err)
888888
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
889889
assert.Equal(t, 2, len(txh.History))
890890
assert.Equal(t, 4, len(txh.DeprecatedHistorySummary))
891891

892892
// Add another that we've seen before
893-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil)
893+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil, fftypes.Now())
894894
assert.NoError(t, err)
895895
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
896896
assert.Equal(t, 3, len(txh.History)) // This goes up
@@ -902,30 +902,30 @@ func TestManagedTXSubStatusAction(t *testing.T) {
902902
defer done()
903903
mtx := newTestTX("0x12345", apitypes.TxStatusPending)
904904

905-
err := p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil)
905+
err := p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
906906
assert.Regexp(t, "FF21067", err)
907907

908908
err = p.InsertTransactionWithNextNonce(ctx, mtx, func(ctx context.Context, signer string) (uint64, error) { return 12345, nil })
909909
assert.NoError(t, err)
910910

911911
// Add an action
912-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil)
912+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
913913
assert.NoError(t, err)
914914
txh, err := p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
915915
assert.NoError(t, err)
916916
assert.Equal(t, 1, len(txh.History[0].Actions))
917917
assert.Nil(t, txh.History[0].Actions[0].LastErrorTime)
918918

919919
// Add another action
920-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, nil, fftypes.JSONAnyPtr(`{"gasError":"Acme Gas Oracle RC=12345"}`))
920+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, nil, fftypes.JSONAnyPtr(`{"gasError":"Acme Gas Oracle RC=12345"}`), fftypes.Now())
921921
assert.NoError(t, err)
922922
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
923923
assert.NoError(t, err)
924924
assert.Equal(t, 2, len(txh.History[0].Actions))
925925
assert.Equal(t, (*txh.History[0].Actions[1].LastError).String(), `{"gasError":"Acme Gas Oracle RC=12345"}`)
926926

927927
// Add the same action which should cause the previous one to inc its counter
928-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, fftypes.JSONAnyPtr(`{"info":"helloworld"}`), fftypes.JSONAnyPtr(`{"error":"nogood"}`))
928+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, fftypes.JSONAnyPtr(`{"info":"helloworld"}`), fftypes.JSONAnyPtr(`{"error":"nogood"}`), fftypes.Now())
929929
assert.NoError(t, err)
930930
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
931931
assert.NoError(t, err)
@@ -934,7 +934,7 @@ func TestManagedTXSubStatusAction(t *testing.T) {
934934
assert.Equal(t, 2, txh.History[0].Actions[1].OccurrenceCount)
935935

936936
// Add the same action but with new error information should update the last error field
937-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, nil, fftypes.JSONAnyPtr(`{"gasError":"Acme Gas Oracle RC=67890"}`))
937+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionRetrieveGasPrice, nil, fftypes.JSONAnyPtr(`{"gasError":"Acme Gas Oracle RC=67890"}`), fftypes.Now())
938938
assert.NoError(t, err)
939939
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
940940
assert.NoError(t, err)
@@ -944,7 +944,7 @@ func TestManagedTXSubStatusAction(t *testing.T) {
944944

945945
// Add a new type of action
946946
reason := "known_transaction"
947-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"reason":"`+reason+`"}`), nil)
947+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"reason":"`+reason+`"}`), nil, fftypes.Now())
948948
assert.NoError(t, err)
949949
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
950950
assert.NoError(t, err)
@@ -956,7 +956,7 @@ func TestManagedTXSubStatusAction(t *testing.T) {
956956
// Add one more type of action
957957

958958
receiptId := "123456"
959-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionReceiveReceipt, fftypes.JSONAnyPtr(`{"receiptId":"`+receiptId+`"}`), nil)
959+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionReceiveReceipt, fftypes.JSONAnyPtr(`{"receiptId":"`+receiptId+`"}`), nil, fftypes.Now())
960960
assert.NoError(t, err)
961961
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
962962
assert.NoError(t, err)
@@ -972,13 +972,13 @@ func TestManagedTXSubStatusAction(t *testing.T) {
972972

973973
// Add some new sub-status and actions to check max lengths are correct
974974
// Seen one of these before - should increase summary length by 1
975-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusConfirmed, apitypes.TxActionReceiveReceipt, fftypes.JSONAnyPtr(`{"receiptId":"`+receiptId+`"}`), nil)
975+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusConfirmed, apitypes.TxActionReceiveReceipt, fftypes.JSONAnyPtr(`{"receiptId":"`+receiptId+`"}`), nil, fftypes.Now())
976976
assert.NoError(t, err)
977977
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
978978
assert.Equal(t, 6, len(txh.DeprecatedHistorySummary))
979979

980980
// Seen both of these before - no change expected
981-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil)
981+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
982982
assert.NoError(t, err)
983983
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
984984
assert.NoError(t, err)
@@ -1070,7 +1070,7 @@ func TestManagedTXSubStatusInvalidJSON(t *testing.T) {
10701070
reason := "\"cannot-marshall\""
10711071

10721072
// Add a new type of action
1073-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"reason":"`+reason+`"}`), nil)
1073+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"reason":"`+reason+`"}`), nil, fftypes.Now())
10741074
assert.NoError(t, err)
10751075
txh, err := p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
10761076
assert.NoError(t, err)
@@ -1095,7 +1095,7 @@ func TestManagedTXSubStatusMaxEntries(t *testing.T) {
10951095
// first 50
10961096
for i := 0; i < 100; i++ {
10971097
nextSubStatus = apitypes.TxSubStatus(fmt.Sprint(i))
1098-
p.AddSubStatusAction(ctx, mtx.ID, nextSubStatus, apitypes.TxActionAssignNonce, nil, nil)
1098+
p.AddSubStatusAction(ctx, mtx.ID, nextSubStatus, apitypes.TxActionAssignNonce, nil, nil, fftypes.Now())
10991099
assert.NoError(t, err)
11001100
}
11011101

@@ -1114,7 +1114,7 @@ func TestMaxHistoryCountSetToZero(t *testing.T) {
11141114
err := p.InsertTransactionWithNextNonce(ctx, mtx, func(ctx context.Context, signer string) (uint64, error) { return 12345, nil })
11151115
assert.NoError(t, err)
11161116

1117-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil)
1117+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil, fftypes.Now())
11181118
assert.NoError(t, err)
11191119

11201120
txh, err := p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)
@@ -1141,7 +1141,7 @@ func TestAddReceivedStatusWhenNothingSet(t *testing.T) {
11411141
assert.NoError(t, err)
11421142
assert.Nil(t, txh.History)
11431143

1144-
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil)
1144+
err = p.AddSubStatusAction(ctx, mtx.ID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, nil, fftypes.Now())
11451145
assert.NoError(t, err)
11461146

11471147
txh, err = p.GetTransactionByIDWithStatus(ctx, mtx.ID, true)

internal/persistence/postgres/transactions_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2023 Kaleido, Inc.
1+
// Copyright © 2024 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -103,13 +103,13 @@ func TestTransactionBasicValidationPSQL(t *testing.T) {
103103
assert.NoError(t, err)
104104

105105
// A couple of transaction history entries
106-
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, fftypes.JSONAnyPtr(`{"nonce":"11111"}`), nil)
106+
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionAssignNonce, fftypes.JSONAnyPtr(`{"nonce":"11111"}`), nil, fftypes.Now())
107107
assert.NoError(t, err)
108-
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, fftypes.JSONAnyPtr(`"failed to submit 1"`))
108+
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, fftypes.JSONAnyPtr(`"failed to submit 1"`), fftypes.Now())
109109
assert.NoError(t, err)
110-
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, fftypes.JSONAnyPtr(`"failed to submit 2"`))
110+
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusReceived, apitypes.TxActionSubmitTransaction, nil, fftypes.JSONAnyPtr(`"failed to submit 2"`), fftypes.Now())
111111
assert.NoError(t, err)
112-
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusTracking, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"txhash":"0x12345"}`), nil)
112+
err = p.AddSubStatusAction(ctx, txID, apitypes.TxSubStatusTracking, apitypes.TxActionSubmitTransaction, fftypes.JSONAnyPtr(`{"txhash":"0x12345"}`), nil, fftypes.Now())
113113
assert.NoError(t, err)
114114

115115
// Finally the update - do a comprehensive one

internal/persistence/postgres/txhistory.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2023 Kaleido, Inc.
1+
// Copyright © 2024 Kaleido, Inc.
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -95,25 +95,25 @@ func (p *sqlPersistence) ListTransactionHistory(ctx context.Context, txID string
9595
return p.txHistory.GetMany(ctx, filter.Condition(filter.Builder().Eq("transaction", txID)))
9696
}
9797

98-
func (p *sqlPersistence) AddSubStatusAction(ctx context.Context, txID string, subStatus apitypes.TxSubStatus, action apitypes.TxAction, info *fftypes.JSONAny, errInfo *fftypes.JSONAny) error {
98+
func (p *sqlPersistence) AddSubStatusAction(ctx context.Context, txID string, subStatus apitypes.TxSubStatus, action apitypes.TxAction, info *fftypes.JSONAny, errInfo *fftypes.JSONAny, actionOccurred *fftypes.FFTime) error {
9999
// Dispatch to TX writer
100-
now := fftypes.Now()
100+
101101
op := newTransactionOperation(txID)
102102
op.historyRecord = &apitypes.TXHistoryRecord{
103103
ID: fftypes.NewUUID(),
104104
TransactionID: txID,
105105
SubStatus: subStatus,
106106
TxHistoryActionEntry: apitypes.TxHistoryActionEntry{
107107
OccurrenceCount: 1,
108-
Time: now,
109-
LastOccurrence: now,
108+
Time: actionOccurred,
109+
LastOccurrence: actionOccurred,
110110
Action: action,
111111
LastInfo: persistence.JSONOrString(info), // guard against bad JSON
112112
LastError: persistence.JSONOrString(errInfo), // guard against bad JSON
113113
},
114114
}
115115
if errInfo != nil {
116-
op.historyRecord.LastErrorTime = fftypes.Now()
116+
op.historyRecord.LastErrorTime = actionOccurred
117117
}
118118
p.writer.queue(ctx, op)
119119
return nil // completely async

0 commit comments

Comments
 (0)