Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rollup-relayer & gas-oracle): graceful restart #1076

Merged
merged 44 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
74e1436
feat(rollup-relayer & gas-oracle): graceful restart
colinlyguo Jan 12, 2024
c9fbabe
fix go import and unit tests
colinlyguo Jan 15, 2024
db2d39b
fix gorm id field
colinlyguo Jan 15, 2024
4fe7b63
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 15, 2024
b7af443
chore: auto version bump [bot]
colinlyguo Jan 15, 2024
88de67b
address comments
colinlyguo Jan 15, 2024
e69d722
fix checkPendingTransaction logic
colinlyguo Jan 15, 2024
356707e
tweak comments
colinlyguo Jan 15, 2024
f22b884
remove sender's blockNumber and baseFeePerGas
colinlyguo Jan 16, 2024
ba3bdc0
increase coverage
colinlyguo Jan 16, 2024
89fb9a8
add orm test
colinlyguo Jan 16, 2024
442c296
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 17, 2024
af946ed
add testSendAndRetrieveTransaction unit test
colinlyguo Jan 17, 2024
7b0495c
tweak
colinlyguo Jan 17, 2024
1dd1d64
add unit tests
colinlyguo Jan 17, 2024
45058d2
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 17, 2024
bc04e46
chore: auto version bump [bot]
colinlyguo Jan 17, 2024
abc20f2
fix unit test
colinlyguo Jan 17, 2024
95034cd
Update help copy
zzq0826 Jan 18, 2024
d25772f
access list bug fix
colinlyguo Jan 17, 2024
9bcf288
tweak
colinlyguo Jan 18, 2024
1093f02
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 22, 2024
98044ee
chore: auto version bump [bot]
colinlyguo Jan 22, 2024
cb4ef0c
fix CI
colinlyguo Jan 22, 2024
77bdca2
fix golint
colinlyguo Jan 22, 2024
61cc6cd
trigger ci
colinlyguo Jan 22, 2024
241ddc5
set tx hash as unique index
colinlyguo Jan 22, 2024
4f08f2a
tweak
colinlyguo Jan 22, 2024
b472e00
tweak
colinlyguo Jan 22, 2024
e2c41aa
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 24, 2024
971f0d1
revert alerts related metrics change
colinlyguo Jan 24, 2024
7752bf8
fix a log bug
colinlyguo Jan 24, 2024
ee46b28
trigger ci
colinlyguo Jan 24, 2024
6a5a448
remove some outdated comments
colinlyguo Jan 24, 2024
a91ca83
Merge branch 'develop' into feat-rollup-relayer-gas-oracle-graceful-r…
colinlyguo Jan 24, 2024
cc94470
remove unused metrics
colinlyguo Jan 24, 2024
dc757ff
simplify db and enhance orm_test
colinlyguo Jan 24, 2024
c874816
refine orm
colinlyguo Jan 24, 2024
0213777
tweak
colinlyguo Jan 24, 2024
80a613b
enhance sender test
colinlyguo Jan 24, 2024
27a02d3
tweak
colinlyguo Jan 24, 2024
6fbe169
fix
colinlyguo Jan 24, 2024
073800a
Apply suggestions from code review
colinlyguo Jan 25, 2024
a900fae
fix db tests
colinlyguo Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 67 additions & 4 deletions common/types/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const (
// GasOracleImported represents the gas oracle status is imported
GasOracleImported

// GasOracleFailed represents the gas oracle status is failed
GasOracleFailed
// GasOracleImportedFailed represents the gas oracle status is imported failed
GasOracleImportedFailed
)

func (s GasOracleStatus) String() string {
Expand All @@ -35,8 +35,8 @@ func (s GasOracleStatus) String() string {
return "GasOracleImporting"
case GasOracleImported:
return "GasOracleImported"
case GasOracleFailed:
return "GasOracleFailed"
case GasOracleImportedFailed:
return "GasOracleImportedFailed"
default:
return fmt.Sprintf("Undefined (%d)", int32(s))
}
Expand Down Expand Up @@ -230,3 +230,66 @@ func (s RollupStatus) String() string {
return fmt.Sprintf("Undefined (%d)", int32(s))
}
}

// SenderType defines the various types of senders sending the transactions.
type SenderType int

const (
// SenderTypeUnknown indicates an unknown sender type.
SenderTypeUnknown SenderType = iota
// SenderTypeCommitBatch indicates the sender is responsible for committing batches.
SenderTypeCommitBatch
// SenderTypeFinalizeBatch indicates the sender is responsible for finalizing batches.
SenderTypeFinalizeBatch
// SenderTypeL1GasOracle indicates a sender from L2 responsible for updating L1 gas prices.
SenderTypeL1GasOracle
// SenderTypeL2GasOracle indicates a sender from L1 responsible for updating L2 gas prices.
SenderTypeL2GasOracle
)

// String returns a string representation of the SenderType.
func (t SenderType) String() string {
switch t {
case SenderTypeCommitBatch:
return "SenderTypeCommitBatch"
case SenderTypeFinalizeBatch:
return "SenderTypeFinalizeBatch"
case SenderTypeL1GasOracle:
return "SenderTypeL1GasOracle"
case SenderTypeL2GasOracle:
return "SenderTypeL2GasOracle"
default:
return fmt.Sprintf("Unknown (%d)", int32(t))
}
}

// TxStatus represents the current status of a transaction in the transaction lifecycle.
type TxStatus int

const (
// TxStatusUnknown represents an undefined status of the transaction.
TxStatusUnknown TxStatus = iota
// TxStatusPending indicates that the transaction is yet to be processed.
TxStatusPending
// TxStatusReplaced indicates that the transaction has been replaced by another one, typically due to a higher gas price.
TxStatusReplaced
// TxStatusConfirmed indicates that the transaction has been successfully processed and confirmed.
TxStatusConfirmed
// TxStatusConfirmedFailed indicates that the transaction has failed during processing.
TxStatusConfirmedFailed
)

func (s TxStatus) String() string {
switch s {
case TxStatusPending:
return "TxStatusPending"
case TxStatusReplaced:
return "TxStatusReplaced"
case TxStatusConfirmed:
return "TxStatusConfirmed"
case TxStatusConfirmedFailed:
return "TxStatusConfirmedFailed"
default:
return fmt.Sprintf("Unknown (%d)", int32(s))
}
}
240 changes: 240 additions & 0 deletions common/types/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,243 @@ func TestProvingStatus(t *testing.T) {
})
}
}

func TestRollupStatus(t *testing.T) {
tests := []struct {
name string
s RollupStatus
want string
}{
{
"RollupUndefined",
RollupUndefined,
"Undefined (0)",
},
{
"RollupPending",
RollupPending,
"RollupPending",
},
{
"RollupCommitting",
RollupCommitting,
"RollupCommitting",
},
{
"RollupCommitted",
RollupCommitted,
"RollupCommitted",
},
{
"RollupFinalizing",
RollupFinalizing,
"RollupFinalizing",
},
{
"RollupFinalized",
RollupFinalized,
"RollupFinalized",
},
{
"RollupCommitFailed",
RollupCommitFailed,
"RollupCommitFailed",
},
{
"RollupFinalizeFailed",
RollupFinalizeFailed,
"RollupFinalizeFailed",
},
{
"Invalid Value",
RollupStatus(999),
"Undefined (999)",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.s.String())
})
}
}

func TestSenderType(t *testing.T) {
tests := []struct {
name string
t SenderType
want string
}{
{
"SenderTypeUnknown",
SenderTypeUnknown,
"Unknown (0)",
},
{
"SenderTypeCommitBatch",
SenderTypeCommitBatch,
"SenderTypeCommitBatch",
},
{
"SenderTypeFinalizeBatch",
SenderTypeFinalizeBatch,
"SenderTypeFinalizeBatch",
},
{
"SenderTypeL1GasOracle",
SenderTypeL1GasOracle,
"SenderTypeL1GasOracle",
},
{
"SenderTypeL2GasOracle",
SenderTypeL2GasOracle,
"SenderTypeL2GasOracle",
},
{
"Invalid Value",
SenderType(999),
"Unknown (999)",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.t.String())
})
}
}

func TestTxStatus(t *testing.T) {
tests := []struct {
name string
s TxStatus
want string
}{
{
"TxStatusUnknown",
TxStatusUnknown,
"Unknown (0)",
},
{
"TxStatusPending",
TxStatusPending,
"TxStatusPending",
},
{
"TxStatusReplaced",
TxStatusReplaced,
"TxStatusReplaced",
},
{
"TxStatusConfirmed",
TxStatusConfirmed,
"TxStatusConfirmed",
},
{
"TxStatusConfirmedFailed",
TxStatusConfirmedFailed,
"TxStatusConfirmedFailed",
},
{
"Invalid Value",
TxStatus(999),
"Unknown (999)",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.s.String())
})
}
}

func TestGasOracleStatus(t *testing.T) {
tests := []struct {
name string
s GasOracleStatus
want string
}{
{
"GasOracleUndefined",
GasOracleUndefined,
"GasOracleUndefined",
},
{
"GasOraclePending",
GasOraclePending,
"GasOraclePending",
},
{
"GasOracleImporting",
GasOracleImporting,
"GasOracleImporting",
},
{
"GasOracleImported",
GasOracleImported,
"GasOracleImported",
},
{
"GasOracleImportedFailed",
GasOracleImportedFailed,
"GasOracleImportedFailed",
},
{
"Invalid Value",
GasOracleStatus(999),
"Undefined (999)",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.s.String())
})
}
}

func TestProverTaskFailureType(t *testing.T) {
tests := []struct {
name string
r ProverTaskFailureType
want string
}{
{
"ProverTaskFailureTypeUndefined",
ProverTaskFailureTypeUndefined,
"prover task failure undefined",
},
{
"ProverTaskFailureTypeTimeout",
ProverTaskFailureTypeTimeout,
"prover task failure timeout",
},
{
"ProverTaskFailureTypeSubmitStatusNotOk",
ProverTaskFailureTypeSubmitStatusNotOk,
"prover task failure validated submit proof status not ok",
},
{
"ProverTaskFailureTypeVerifiedFailed",
ProverTaskFailureTypeVerifiedFailed,
"prover task failure verified failed",
},
{
"ProverTaskFailureTypeServerError",
ProverTaskFailureTypeServerError,
"prover task failure server exception",
},
{
"Invalid Value",
ProverTaskFailureType(999),
"illegal prover task failure type (999)",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, tt.r.String())
})
}
}
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.3.58"
var tag = "v4.3.59"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
2 changes: 1 addition & 1 deletion database/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func testResetDB(t *testing.T) {
cur, err := Current(pgDB.DB)
assert.NoError(t, err)
// total number of tables.
assert.Equal(t, 14, int(cur))
assert.Equal(t, 15, int(cur))
}

func testMigrate(t *testing.T) {
Expand Down
46 changes: 46 additions & 0 deletions database/migrate/migrations/00015_pending_transaction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- +goose Up
-- +goose StatementBegin

CREATE TABLE pending_transaction
(
id SERIAL PRIMARY KEY,

-- context info
context_id VARCHAR NOT NULL, -- batch hash in commit/finalize tx, block hash in update gas oracle tx
hash VARCHAR NOT NULL,
status SMALLINT NOT NULL,
rlp_encoding BYTEA NOT NULL,

-- debug info
chain_id BIGINT NOT NULL,
type SMALLINT NOT NULL,
gas_tip_cap BIGINT NOT NULL,
gas_fee_cap BIGINT NOT NULL, -- based on geth's implementation, it's gas price in legacy tx.
gas_limit BIGINT NOT NULL,
nonce BIGINT NOT NULL,
submit_block_number BIGINT NOT NULL,

-- sender info
sender_name VARCHAR NOT NULL,
sender_service VARCHAR NOT NULL,
sender_address VARCHAR NOT NULL,
sender_type SMALLINT NOT NULL,

created_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at TIMESTAMP(0) DEFAULT NULL
);

CREATE UNIQUE INDEX unique_idx_pending_transaction_on_hash ON pending_transaction(hash);
CREATE INDEX idx_pending_transaction_on_sender_type_status_nonce_gas_fee_cap ON pending_transaction (sender_type, status, nonce, gas_fee_cap);
CREATE INDEX idx_pending_transaction_on_sender_address_nonce ON pending_transaction(sender_address, nonce);

COMMENT ON COLUMN pending_transaction.sender_type IS 'unknown, commit batch, finalize batch, L1 gas oracle, L2 gas oracle';
COMMENT ON COLUMN pending_transaction.status IS 'unknown, pending, replaced, confirmed, confirmed failed';

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS pending_transaction;
-- +goose StatementEnd
Loading
Loading