Skip to content

Commit 5afe386

Browse files
committed
remove: dataProvider
1 parent f201cbf commit 5afe386

6 files changed

Lines changed: 35 additions & 89 deletions

File tree

cmd/tss/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/pushchain/push-chain-node/universalClient/pushcore"
2424
"github.com/pushchain/push-chain-node/universalClient/store"
2525
"github.com/pushchain/push-chain-node/universalClient/tss"
26-
"github.com/pushchain/push-chain-node/universalClient/tss/coordinator"
2726
"github.com/pushchain/push-chain-node/universalClient/tss/eventstore"
2827
"github.com/pushchain/push-chain-node/x/uvalidator/types"
2928
)
@@ -233,20 +232,18 @@ func runNode() {
233232
}
234233
defer database.Close()
235234

236-
// Create data provider - use PushCoreDataProvider if gRPC URL is provided
237-
var dataProvider coordinator.DataProvider
235+
// Create pushcore client - required for TSS node
236+
var pushClient *pushcore.Client
238237
var tssListener *push.PushTSSEventListener
239238
if *grpcURL != "" {
240239
// Create pushcore client directly
241-
pushClient, err := pushcore.New([]string{*grpcURL}, logger)
240+
var err error
241+
pushClient, err = pushcore.New([]string{*grpcURL}, logger)
242242
if err != nil {
243243
logger.Fatal().Err(err).Str("grpc_url", *grpcURL).Msg("failed to create pushcore client")
244244
}
245245
defer pushClient.Close()
246-
247-
// Create data provider using the client
248-
dataProvider = NewPushCoreDataProvider(pushClient, logger)
249-
logger.Info().Str("grpc_url", *grpcURL).Msg("using pushcore data provider (connected to blockchain)")
246+
logger.Info().Str("grpc_url", *grpcURL).Msg("using pushcore client (connected to blockchain)")
250247

251248
// Create event store from database
252249
evtStore := eventstore.NewStore(database.Client(), logger)
@@ -259,8 +256,12 @@ func runNode() {
259256
defer tssListener.Stop()
260257
logger.Info().Msg("started Push TSS event listener")
261258
} else {
262-
dataProvider = NewStaticPushChainDataProvider(*validatorAddr, logger)
263-
logger.Info().Msg("using static data provider (demo mode)")
259+
// For demo mode, we still need a pushcore client, but we'll use static data
260+
// Create a dummy client (this won't work for real operations, but allows the code to compile)
261+
// In practice, grpcURL should always be provided
262+
logger.Warn().Msg("no gRPC URL provided - TSS node requires pushcore client")
263+
// We'll need to handle this case - for now, let's require grpcURL
264+
logger.Fatal().Msg("gRPC URL is required for TSS node")
264265
}
265266

266267
// Initialize TSS node
@@ -271,7 +272,7 @@ func runNode() {
271272
HomeDir: *homeDir,
272273
Password: *password,
273274
Database: database,
274-
DataProvider: dataProvider,
275+
PushCore: pushClient,
275276
Logger: logger,
276277
PollInterval: 2 * time.Second,
277278
ProcessingTimeout: 2 * time.Minute,

universalClient/core/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ func NewUniversalClient(ctx context.Context, log zerolog.Logger, dbManager *db.C
174174
tssHomeDir = filepath.Join(homeDir, ".puniversal", "tss")
175175
}
176176

177-
// Create TSS data provider using pushcore
178-
tssDataProvider := pushcore.NewDataProvider(pushCore, log)
179-
180177
// Create TSS node configuration
181178
tssCfg := tss.Config{
182179
ValidatorAddress: validatorAddr,
@@ -185,7 +182,7 @@ func NewUniversalClient(ctx context.Context, log zerolog.Logger, dbManager *db.C
185182
HomeDir: tssHomeDir,
186183
Password: cfg.TSSPassword,
187184
Database: tssDB,
188-
DataProvider: tssDataProvider,
185+
PushCore: pushCore,
189186
Logger: log,
190187
}
191188

universalClient/pushcore/dataprovider.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

universalClient/tss/coordinator/coordinator.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
session "go-wrapper/go-dkls/sessions"
1515

16+
"github.com/pushchain/push-chain-node/universalClient/pushcore"
1617
"github.com/pushchain/push-chain-node/universalClient/store"
1718
"github.com/pushchain/push-chain-node/universalClient/tss/eventstore"
1819
"github.com/pushchain/push-chain-node/universalClient/tss/keyshare"
@@ -22,7 +23,7 @@ import (
2223
// Coordinator handles coordinator logic for TSS events.
2324
type Coordinator struct {
2425
eventStore *eventstore.Store
25-
dataProvider DataProvider
26+
pushCore *pushcore.Client
2627
keyshareManager *keyshare.Manager
2728
validatorAddress string
2829
coordinatorRange uint64
@@ -51,7 +52,7 @@ type ackState struct {
5152
// NewCoordinator creates a new coordinator.
5253
func NewCoordinator(
5354
eventStore *eventstore.Store,
54-
dataProvider DataProvider,
55+
pushCore *pushcore.Client,
5556
keyshareManager *keyshare.Manager,
5657
validatorAddress string,
5758
coordinatorRange uint64,
@@ -64,7 +65,7 @@ func NewCoordinator(
6465
}
6566
return &Coordinator{
6667
eventStore: eventStore,
67-
dataProvider: dataProvider,
68+
pushCore: pushCore,
6869
keyshareManager: keyshareManager,
6970
validatorAddress: validatorAddress,
7071
coordinatorRange: coordinatorRange,
@@ -155,15 +156,15 @@ func (c *Coordinator) GetMultiAddrsFromPeerID(ctx context.Context, peerID string
155156
return nil, errors.Errorf("peerID %s not found in validators", peerID)
156157
}
157158

158-
// GetLatestBlockNum gets the latest block number from the data provider.
159+
// GetLatestBlockNum gets the latest block number from pushCore.
159160
func (c *Coordinator) GetLatestBlockNum() (uint64, error) {
160-
return c.dataProvider.GetLatestBlockNum()
161+
return c.pushCore.GetLatestBlockNum()
161162
}
162163

163164
// IsPeerCoordinator checks if the given peerID is the coordinator for the current block.
164165
// Uses cached allValidators for performance.
165166
func (c *Coordinator) IsPeerCoordinator(ctx context.Context, peerID string) (bool, error) {
166-
currentBlock, err := c.dataProvider.GetLatestBlockNum()
167+
currentBlock, err := c.pushCore.GetLatestBlockNum()
167168
if err != nil {
168169
return false, errors.Wrap(err, "failed to get latest block number")
169170
}
@@ -210,9 +211,9 @@ func (c *Coordinator) IsPeerCoordinator(ctx context.Context, peerID string) (boo
210211
return coordValidatorAddr == validatorAddress, nil
211212
}
212213

213-
// GetCurrentTSSKeyId gets the current TSS key ID from the data provider.
214+
// GetCurrentTSSKeyId gets the current TSS key ID from pushCore.
214215
func (c *Coordinator) GetCurrentTSSKeyId() (string, error) {
215-
return c.dataProvider.GetCurrentTSSKeyId()
216+
return c.pushCore.GetCurrentTSSKeyId()
216217
}
217218

218219
// GetEligibleUV returns eligible validators for the given protocol type.
@@ -293,7 +294,7 @@ func (c *Coordinator) pollLoop(ctx context.Context) {
293294

294295
// updateValidators fetches and caches all validators.
295296
func (c *Coordinator) updateValidators() {
296-
allValidators, err := c.dataProvider.GetUniversalValidators()
297+
allValidators, err := c.pushCore.GetUniversalValidators()
297298
if err != nil {
298299
c.logger.Warn().Err(err).Msg("failed to update validators cache")
299300
return
@@ -308,7 +309,7 @@ func (c *Coordinator) updateValidators() {
308309

309310
// processPendingEvents checks if this node is coordinator, and only then reads DB and processes events.
310311
func (c *Coordinator) processPendingEvents(ctx context.Context) error {
311-
currentBlock, err := c.dataProvider.GetLatestBlockNum()
312+
currentBlock, err := c.pushCore.GetLatestBlockNum()
312313
if err != nil {
313314
return errors.Wrap(err, "failed to get latest block number")
314315
}
@@ -605,8 +606,8 @@ func (c *Coordinator) createKeygenSetup(threshold int, partyIDs []string) ([]byt
605606
// createSignSetup creates a sign setup message.
606607
// Requires loading the keyshare to extract keyID and messageHash from event data.
607608
func (c *Coordinator) createSignSetup(ctx context.Context, eventData []byte, partyIDs []string) ([]byte, error) {
608-
// Get current TSS keyId from dataProvider
609-
keyIDStr, err := c.dataProvider.GetCurrentTSSKeyId()
609+
// Get current TSS keyId from pushCore
610+
keyIDStr, err := c.pushCore.GetCurrentTSSKeyId()
610611
if err != nil {
611612
return nil, errors.Wrap(err, "failed to get current TSS keyId")
612613
}
@@ -665,8 +666,8 @@ func (c *Coordinator) createSignSetup(ctx context.Context, eventData []byte, par
665666
// oldParticipantIndices: indices of Active validators (staying participants)
666667
// newParticipantIndices: indices of Pending Join validators (new participants)
667668
func (c *Coordinator) createQcSetup(ctx context.Context, threshold int, partyIDs []string, participants []*types.UniversalValidator) ([]byte, error) {
668-
// Get current TSS keyId from dataProvider
669-
keyIDStr, err := c.dataProvider.GetCurrentTSSKeyId()
669+
// Get current TSS keyId from pushCore
670+
keyIDStr, err := c.pushCore.GetCurrentTSSKeyId()
670671
if err != nil {
671672
return nil, errors.Wrap(err, "failed to get current TSS keyId")
672673
}

universalClient/tss/coordinator/types.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,13 @@ package coordinator
22

33
import (
44
"context"
5-
6-
"github.com/pushchain/push-chain-node/x/uvalidator/types"
75
)
86

97
// SendFunc is a function type for sending messages to participants.
108
// peerID: The peer ID of the recipient
119
// data: The message bytes
1210
type SendFunc func(ctx context.Context, peerID string, data []byte) error
1311

14-
// DataProvider provides access to Push Chain data.
15-
type DataProvider interface {
16-
GetLatestBlockNum() (uint64, error)
17-
GetUniversalValidators() ([]*types.UniversalValidator, error)
18-
GetCurrentTSSKeyId() (string, error)
19-
}
20-
2112
// ProtocolType enumerates the supported DKLS protocol flows.
2213
type ProtocolType string
2314

universalClient/tss/tss.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/rs/zerolog"
1717

1818
"github.com/pushchain/push-chain-node/universalClient/db"
19+
"github.com/pushchain/push-chain-node/universalClient/pushcore"
1920
"github.com/pushchain/push-chain-node/universalClient/tss/coordinator"
2021
"github.com/pushchain/push-chain-node/universalClient/tss/eventstore"
2122
"github.com/pushchain/push-chain-node/universalClient/tss/keyshare"
@@ -32,7 +33,7 @@ type Config struct {
3233
HomeDir string
3334
Password string
3435
Database *db.DB
35-
DataProvider coordinator.DataProvider
36+
PushCore *pushcore.Client
3637
Logger zerolog.Logger
3738

3839
// Optional configuration
@@ -86,7 +87,7 @@ type Node struct {
8687
network networking.Network
8788
keyshareManager *keyshare.Manager
8889
database *db.DB
89-
dataProvider coordinator.DataProvider
90+
pushCore *pushcore.Client
9091
logger zerolog.Logger
9192
eventStore *eventstore.Store
9293
coordinator *coordinator.Coordinator
@@ -123,8 +124,8 @@ func NewNode(ctx context.Context, cfg Config) (*Node, error) {
123124
if cfg.P2PPrivateKeyHex == "" {
124125
return nil, fmt.Errorf("private key is required")
125126
}
126-
if cfg.DataProvider == nil {
127-
return nil, fmt.Errorf("data provider is required")
127+
if cfg.PushCore == nil {
128+
return nil, fmt.Errorf("pushCore is required")
128129
}
129130
if cfg.HomeDir == "" {
130131
return nil, fmt.Errorf("home directory is required")
@@ -211,7 +212,7 @@ func NewNode(ctx context.Context, cfg Config) (*Node, error) {
211212
validatorAddress: cfg.ValidatorAddress,
212213
keyshareManager: mgr,
213214
database: database,
214-
dataProvider: cfg.DataProvider,
215+
pushCore: cfg.PushCore,
215216
logger: logger,
216217
eventStore: evtStore,
217218
sessionManager: nil, // Will be initialized in Start()
@@ -274,7 +275,7 @@ func (n *Node) Start(ctx context.Context) error {
274275
if n.coordinator == nil {
275276
coord := coordinator.NewCoordinator(
276277
n.eventStore,
277-
n.dataProvider,
278+
n.pushCore,
278279
n.keyshareManager,
279280
n.validatorAddress,
280281
n.coordinatorRange,

0 commit comments

Comments
 (0)