Skip to content

Commit d8ab2e1

Browse files
committed
[PSL-1256] handle multi-vol ticket reg & act confirmations edge cases
1 parent d479a9b commit d8ab2e1

File tree

19 files changed

+33848
-32355
lines changed

19 files changed

+33848
-32355
lines changed

common/storage/ticketstore/activation_attempts.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package ticketstore
22

33
import (
4-
"github.com/pastelnetwork/gonode/common/types"
4+
"database/sql"
55
"time"
6+
7+
"github.com/pastelnetwork/gonode/common/types"
68
)
79

810
type ActivationAttemptsQueries interface {
@@ -16,14 +18,14 @@ type ActivationAttemptsQueries interface {
1618
func (s *TicketStore) InsertActivationAttempt(attempt types.ActivationAttempt) (int64, error) {
1719
const insertQuery = `
1820
INSERT INTO activation_attempts (
19-
file_id, base_file_id, activation_attempt_at, is_successful, error_message, created_at, updated_at
20-
) VALUES (?, ?, ?, ?, ?, ?, ?)
21+
file_id, base_file_id, activation_attempt_at, is_successful, is_confirmed, error_message, created_at, updated_at
22+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
2123
RETURNING id;`
2224

2325
var id int64
2426
err := s.db.QueryRow(insertQuery,
2527
attempt.FileID, attempt.BaseFileID, attempt.ActivationAttemptAt,
26-
attempt.IsSuccessful, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
28+
attempt.IsSuccessful, attempt.IsConfirmed, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
2729
if err != nil {
2830
return 0, err
2931
}
@@ -58,27 +60,35 @@ func (s *TicketStore) UpdateActivationAttempt(attempt types.ActivationAttempt) (
5860
// GetActivationAttemptByID retrieves an activation attempt by its ID from the activation_attempts table
5961
func (s *TicketStore) GetActivationAttemptByID(id int) (*types.ActivationAttempt, error) {
6062
const selectQuery = `
61-
SELECT id, file_id, activation_attempt_at, is_successful, error_message
63+
SELECT id, file_id, activation_attempt_at, is_successful, is_confirmed, error_message
6264
FROM activation_attempts
6365
WHERE id = ?;`
6466

6567
row := s.db.QueryRow(selectQuery, int64(id))
6668

67-
var attempt types.ActivationAttempt
69+
var (
70+
attempt types.ActivationAttempt
71+
isConfirmed sql.NullBool
72+
)
6873
err := row.Scan(
6974
&attempt.ID, &attempt.FileID, &attempt.ActivationAttemptAt,
70-
&attempt.IsSuccessful, &attempt.ErrorMessage)
75+
&attempt.IsSuccessful, &isConfirmed, &attempt.ErrorMessage)
7176
if err != nil {
7277
return nil, err
7378
}
7479

80+
attempt.IsConfirmed = false
81+
if isConfirmed.Valid {
82+
attempt.IsConfirmed = isConfirmed.Bool
83+
}
84+
7585
return &attempt, nil
7686
}
7787

7888
// GetActivationAttemptsByFileIDAndBaseFileID retrieves activation attempts by file_id from the activation_attempts table
7989
func (s *TicketStore) GetActivationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.ActivationAttempt, error) {
8090
const selectQuery = `
81-
SELECT id, file_id, activation_attempt_at, is_successful, error_message
91+
SELECT id, file_id, activation_attempt_at, is_successful, is_confirmed, error_message
8292
FROM activation_attempts
8393
WHERE file_id = ? and base_file_id=?;`
8494

@@ -90,13 +100,22 @@ func (s *TicketStore) GetActivationAttemptsByFileIDAndBaseFileID(fileID, baseFil
90100

91101
var attempts []*types.ActivationAttempt
92102
for rows.Next() {
93-
var attempt types.ActivationAttempt
103+
var (
104+
attempt types.ActivationAttempt
105+
isConfirmed sql.NullBool
106+
)
94107
err := rows.Scan(
95108
&attempt.ID, &attempt.FileID, &attempt.ActivationAttemptAt,
96-
&attempt.IsSuccessful, &attempt.ErrorMessage)
109+
&attempt.IsSuccessful, &isConfirmed, &attempt.ErrorMessage)
97110
if err != nil {
98111
return nil, err
99112
}
113+
114+
attempt.IsConfirmed = false
115+
if isConfirmed.Valid {
116+
attempt.IsConfirmed = isConfirmed.Bool
117+
}
118+
100119
attempts = append(attempts, &attempt)
101120
}
102121

common/storage/ticketstore/registration_attempts.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package ticketstore
22

33
import (
4-
"github.com/pastelnetwork/gonode/common/types"
4+
"database/sql"
55
"time"
6+
7+
"github.com/pastelnetwork/gonode/common/types"
68
)
79

810
type RegistrationAttemptsQueries interface {
@@ -16,14 +18,14 @@ type RegistrationAttemptsQueries interface {
1618
func (s *TicketStore) InsertRegistrationAttempt(attempt types.RegistrationAttempt) (int64, error) {
1719
const insertQuery = `
1820
INSERT INTO registration_attempts (
19-
file_id, base_file_id, reg_started_at, processor_sns, finished_at, is_successful, error_message, created_at, updated_at
20-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
21+
file_id, base_file_id, reg_started_at, processor_sns, finished_at, is_successful, is_confirmed, error_message, created_at, updated_at
22+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2123
RETURNING id;`
2224

2325
var id int64
2426
err := s.db.QueryRow(insertQuery,
2527
attempt.FileID, attempt.BaseFileID, attempt.RegStartedAt, attempt.ProcessorSNS,
26-
attempt.FinishedAt, attempt.IsSuccessful, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
28+
attempt.FinishedAt, attempt.IsSuccessful, attempt.IsConfirmed, attempt.ErrorMessage, time.Now().UTC(), time.Now().UTC()).Scan(&id)
2729
if err != nil {
2830
return 0, err
2931
}
@@ -61,28 +63,36 @@ func (s *TicketStore) UpdateRegistrationAttempt(attempt types.RegistrationAttemp
6163
func (s *TicketStore) GetRegistrationAttemptByID(id int) (*types.RegistrationAttempt, error) {
6264
const selectQuery = `
6365
SELECT id, file_id, reg_started_at, processor_sns, finished_at,
64-
is_successful, error_message
66+
is_successful, is_confirmed, error_message
6567
FROM registration_attempts
6668
WHERE id = ?;`
6769

6870
row := s.db.QueryRow(selectQuery, int64(id))
71+
var (
72+
isConfirmed sql.NullBool
73+
attempt types.RegistrationAttempt
74+
)
6975

70-
var attempt types.RegistrationAttempt
7176
err := row.Scan(
7277
&attempt.ID, &attempt.FileID, &attempt.RegStartedAt, &attempt.ProcessorSNS,
73-
&attempt.FinishedAt, &attempt.IsSuccessful, &attempt.ErrorMessage)
78+
&attempt.FinishedAt, &attempt.IsSuccessful, &isConfirmed, &attempt.ErrorMessage)
7479
if err != nil {
7580
return nil, err
7681
}
7782

83+
attempt.IsConfirmed = false
84+
if isConfirmed.Valid {
85+
attempt.IsConfirmed = isConfirmed.Bool
86+
}
87+
7888
return &attempt, nil
7989
}
8090

8191
// GetRegistrationAttemptsByFileIDAndBaseFileID retrieves registration attempts by file_id and baseFileID from the registration_attempts table
8292
func (s *TicketStore) GetRegistrationAttemptsByFileIDAndBaseFileID(fileID, baseFileID string) ([]*types.RegistrationAttempt, error) {
8393
const selectQuery = `
8494
SELECT id, file_id, base_file_id, reg_started_at, processor_sns, finished_at,
85-
is_successful, error_message
95+
is_successful, is_confirmed, error_message
8696
FROM registration_attempts
8797
WHERE file_id = ? and base_file_id=?;`
8898

@@ -94,13 +104,21 @@ func (s *TicketStore) GetRegistrationAttemptsByFileIDAndBaseFileID(fileID, baseF
94104

95105
var attempts []*types.RegistrationAttempt
96106
for rows.Next() {
97-
var attempt types.RegistrationAttempt
107+
var (
108+
attempt types.RegistrationAttempt
109+
isConfirmed sql.NullBool
110+
)
98111
err := rows.Scan(
99112
&attempt.ID, &attempt.FileID, &attempt.BaseFileID, &attempt.RegStartedAt, &attempt.ProcessorSNS,
100-
&attempt.FinishedAt, &attempt.IsSuccessful, &attempt.ErrorMessage)
113+
&attempt.FinishedAt, &attempt.IsSuccessful, &isConfirmed, &attempt.ErrorMessage)
101114
if err != nil {
102115
return nil, err
103116
}
117+
attempt.IsConfirmed = false
118+
if isConfirmed.Valid {
119+
attempt.IsConfirmed = isConfirmed.Bool
120+
}
121+
104122
attempts = append(attempts, &attempt)
105123
}
106124

mixins/pasteld_handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ func (pt *PastelHandler) WaitConfirmation(ctx context.Context, txid string, minC
422422

423423
txResult, err := pt.PastelClient.GetRawTransactionVerbose1(gctx, txid)
424424
if err != nil {
425+
if strings.Contains(err.Error(), "No such mempool or blockchain transaction") {
426+
ch <- errors.Errorf("No such mempool or blockchain transaction. Use gettransaction for wallet transactions.")
427+
return
428+
}
425429
log.WithContext(ctx).WithError(err).WithField("txid", txid).Error("GetRawTransactionVerbose1 err")
426430
} else {
427431
if txResult.Confirmations >= minConfirmation {

walletnode/api/design/cascade.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ var RegistrationAttempt = Type("RegistrationAttempt", func() {
505505
Format(FormatDateTime)
506506
})
507507
Attribute("is_successful", Boolean, "Indicates if the registration was successful")
508+
Attribute("is_confirmed", Boolean, "Indicates if the reg-tx-id is confirmed")
508509
Attribute("error_message", String, "Error Message")
509510
Required("id", "file_id", "reg_started_at", "finished_at")
510511
})
@@ -516,6 +517,7 @@ var ActivationAttempt = Type("ActivationAttempt", func() {
516517
Format(FormatDateTime)
517518
})
518519
Attribute("is_successful", Boolean, "Indicates if the activation was successful")
520+
Attribute("is_confirmed", Boolean, "Indicates if the act-tx-id is confirmed")
519521
Attribute("error_message", String, "Error Message")
520522
Required("id", "file_id", "activation_attempt_at")
521523
})

walletnode/api/gen/cascade/service.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/cascade/views/view.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/cascade/client/cli.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/cascade/client/encode_decode.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/cascade/client/types.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/cascade/server/encode_decode.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/cascade/server/types.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/nft/client/cli.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

walletnode/api/gen/http/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)