@@ -264,6 +264,75 @@ func (s *E2ETestSuite) RegisterPeers(t *testing.T) {
264264 t .Log ("Peer listing completed" )
265265}
266266
267+ // SeedPreParams loads pre-generated ECDSA pre-parameters from fixture files
268+ // and writes them into each node's BadgerDB. This avoids the expensive safe-prime
269+ // generation at node startup which can take minutes on CI runners.
270+ func (s * E2ETestSuite ) SeedPreParams (t * testing.T ) {
271+ t .Log ("Seeding pre-generated pre-params into node databases..." )
272+
273+ // Load fixture files
274+ fixtureData := make ([][]byte , 2 )
275+ for i := 0 ; i < 2 ; i ++ {
276+ path := filepath .Join (s .testDir , "fixtures" , fmt .Sprintf ("pre_params_%d.json" , i ))
277+ data , err := os .ReadFile (path )
278+ if err != nil {
279+ t .Logf ("Warning: could not read pre-params fixture %s: %v (nodes will generate their own)" , path , err )
280+ return
281+ }
282+ fixtureData [i ] = data
283+ }
284+
285+ // Read the badger password from a node config
286+ configPath := filepath .Join (s .testDir , "test_node0" , "config.yaml" )
287+ configData , err := os .ReadFile (configPath )
288+ require .NoError (t , err , "Failed to read node config for badger password" )
289+
290+ var nodeConfig struct {
291+ BadgerPassword string `yaml:"badger_password"`
292+ DbPath string `yaml:"db_path"`
293+ }
294+ require .NoError (t , yaml .Unmarshal (configData , & nodeConfig ), "Failed to parse node config" )
295+
296+ dbBasePath := nodeConfig .DbPath
297+ if dbBasePath == "" {
298+ dbBasePath = "./db"
299+ }
300+
301+ for i := 0 ; i < numNodes ; i ++ {
302+ nodeName := fmt .Sprintf ("test_node%d" , i )
303+ nodeDir := filepath .Join (s .testDir , nodeName )
304+ dbPath := filepath .Join (nodeDir , dbBasePath , nodeName )
305+
306+ // Ensure the DB directory exists
307+ require .NoError (t , os .MkdirAll (dbPath , 0755 ), "Failed to create DB directory for %s" , nodeName )
308+
309+ // Open BadgerDB with the same options the node uses
310+ opts := badger .DefaultOptions (dbPath ).
311+ WithCompression (options .ZSTD ).
312+ WithEncryptionKey ([]byte (nodeConfig .BadgerPassword )).
313+ WithIndexCacheSize (16 << 20 ).
314+ WithBlockCacheSize (32 << 20 ).
315+ WithLogger (nil )
316+
317+ db , err := badger .Open (opts )
318+ require .NoError (t , err , "Failed to open BadgerDB for %s" , nodeName )
319+
320+ // Write pre-params
321+ for j := 0 ; j < 2 ; j ++ {
322+ key := fmt .Sprintf ("pre_params_%d" , j )
323+ err := db .Update (func (txn * badger.Txn ) error {
324+ return txn .Set ([]byte (key ), fixtureData [j ])
325+ })
326+ require .NoError (t , err , "Failed to seed %s for %s" , key , nodeName )
327+ }
328+
329+ require .NoError (t , db .Close (), "Failed to close BadgerDB for %s" , nodeName )
330+ t .Logf ("Seeded pre-params for %s" , nodeName )
331+ }
332+
333+ t .Log ("Pre-params seeding complete" )
334+ }
335+
267336func (s * E2ETestSuite ) StartNodes (t * testing.T ) {
268337 t .Log ("Starting MPC nodes..." )
269338
0 commit comments