Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 12 additions & 10 deletions universalClient/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UniversalClient struct {
pushCore *pushcore.Client
pushSigner *pushsigner.Signer
chains *externalchains.Chains
pushChain *pushwatcher.Client
pushWatcher *pushwatcher.Client
tssNode *tss.Node
}

Expand Down Expand Up @@ -70,21 +70,23 @@ func NewUniversalClient(ctx context.Context, cfg *config.Config) (*UniversalClie

chainsManager := externalchains.NewChains(pushCore, pushSigner, cfg, log)

// Push chain DB is shared by the push chain client and the TSS node.
// Push chain DB is shared by the push watcher and the TSS node.
pushDB, err := openPushDB(cfg)
if err != nil {
return nil, err
}

pushChain, err := pushwatcher.NewClient(
pushWatcher, err := pushwatcher.NewClient(
pushDB,
cfg.GetChainConfig(cfg.PushChainID),
pushCore,
cfg.PushChainID,
log,
pushSigner,
chainsManager,
)
if err != nil {
return nil, fmt.Errorf("failed to create push chain client: %w", err)
return nil, fmt.Errorf("failed to create push watcher: %w", err)
}

tssNode, err := initTSS(ctx, cfg, pushCore, chainsManager, pushSigner, pushDB, log)
Expand All @@ -102,7 +104,7 @@ func NewUniversalClient(ctx context.Context, cfg *config.Config) (*UniversalClie
pushCore: pushCore,
pushSigner: pushSigner,
chains: chainsManager,
pushChain: pushChain,
pushWatcher: pushWatcher,
tssNode: tssNode,
}, nil
}
Expand Down Expand Up @@ -130,8 +132,8 @@ func (uc *UniversalClient) Start() error {
return fmt.Errorf("failed to start chains manager: %w", err)
}

if err := uc.pushChain.Start(uc.ctx); err != nil {
return fmt.Errorf("failed to start push chain client: %w", err)
if err := uc.pushWatcher.Start(uc.ctx); err != nil {
return fmt.Errorf("failed to start push watcher: %w", err)
}

if uc.tssNode != nil {
Expand Down Expand Up @@ -166,9 +168,9 @@ func (uc *UniversalClient) shutdown() {
}
}

if uc.pushChain != nil {
if err := uc.pushChain.Stop(); err != nil {
uc.log.Error().Err(err).Str("subsystem", "push_chain").Msg("subsystem failed to stop")
if uc.pushWatcher != nil {
if err := uc.pushWatcher.Stop(); err != nil {
uc.log.Error().Err(err).Str("subsystem", "push_watcher").Msg("subsystem failed to stop")
}
}

Expand Down
3 changes: 3 additions & 0 deletions universalClient/externalchains/chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ type mockChainClient struct {
func (m *mockChainClient) Start(ctx context.Context) error { m.startCalled = true; return nil }
func (m *mockChainClient) Stop() error { m.stopCalled = true; return m.stopErr }
func (m *mockChainClient) IsHealthy() bool { return true }
func (m *mockChainClient) GetReadRequestHandler() (common.ReadRequestHandler, error) {
return nil, nil
}
func (m *mockChainClient) GetTxBuilder() (common.TxBuilder, error) {
return nil, nil
}
Expand Down
18 changes: 0 additions & 18 deletions universalClient/externalchains/common/chain_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,6 @@ func (cs *ChainStore) UpdateStatusAndEventData(eventID, oldStatus, newStatus str
return res.RowsAffected, nil
}

// UpdateVoteTxHash updates the vote_tx_hash field for an event
func (cs *ChainStore) UpdateVoteTxHash(eventID string, voteTxHash string) error {
if cs.database == nil {
return fmt.Errorf("database is nil")
}

result := cs.database.Client().
Model(&store.Event{}).
Where("event_id = ?", eventID).
Update("vote_tx_hash", voteTxHash)

if result.Error != nil {
return fmt.Errorf("failed to update vote_tx_hash: %w", result.Error)
}

return nil
}

// DeleteTerminalEvents deletes events in terminal states (COMPLETED, REVERTED, EXPIRED)
// that were updated before the given time
func (cs *ChainStore) DeleteTerminalEvents(updatedBefore any) (int64, error) {
Expand Down
23 changes: 0 additions & 23 deletions universalClient/externalchains/common/chain_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ func TestChainStoreNilDatabase(t *testing.T) {
assert.Contains(t, err.Error(), "database is nil")
})

t.Run("UpdateVoteTxHash returns error for nil database", func(t *testing.T) {
err := store.UpdateVoteTxHash("event-1", "0x123")
require.Error(t, err)
assert.Contains(t, err.Error(), "database is nil")
})

t.Run("InsertEventIfNotExists returns error for nil database", func(t *testing.T) {
inserted, err := store.InsertEventIfNotExists(nil)
require.Error(t, err)
Expand Down Expand Up @@ -222,23 +216,6 @@ func TestChainStore_UpdateStatusAndEventData(t *testing.T) {
assert.Equal(t, int64(1), rows)
}

func TestChainStore_UpdateVoteTxHash(t *testing.T) {
cs := newTestChainStore(t)

event := &storemodels.Event{
EventID: "evt-5",
BlockHeight: 50,
Type: storemodels.EventTypeOutbound,
ConfirmationType: storemodels.ConfirmationStandard,
Status: storemodels.StatusConfirmed,
}
_, err := cs.InsertEventIfNotExists(event)
require.NoError(t, err)

err = cs.UpdateVoteTxHash("evt-5", "0xvotehash")
require.NoError(t, err)
}

func TestChainStore_GetPendingEventsLimit(t *testing.T) {
cs := newTestChainStore(t)

Expand Down
Loading
Loading