@@ -293,7 +293,8 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
293293 const totalSupply = await this . #seedWallets( options ) ;
294294
295295 // 2) Seed validators
296- const { importedValidators, skippedValidators } = await this . #seedValidators( options ) ;
296+ const { importedValidatorsWithBlsKey, importedValidatorsWithoutBlsKey, skippedValidators } =
297+ await this . #seedValidators( options ) ;
297298
298299 // 3) Seed voters
299300 const { importedVoters, skippedVoters } = await this . #seedVoters( options ) ;
@@ -307,7 +308,8 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
307308
308309 return {
309310 importedUsernames,
310- importedValidators,
311+ importedValidatorsWithBlsKey,
312+ importedValidatorsWithoutBlsKey,
311313 importedVoters,
312314 initialTotalSupply : totalSupply ,
313315 skippedValidators,
@@ -353,15 +355,18 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
353355 return totalSupply ;
354356 }
355357
356- async #seedValidators(
357- options : Contracts . Snapshot . LegacyImportOptions ,
358- ) : Promise < { importedValidators : number ; skippedValidators : number } > {
358+ async #seedValidators( options : Contracts . Snapshot . LegacyImportOptions ) : Promise < {
359+ importedValidatorsWithBlsKey : number ;
360+ importedValidatorsWithoutBlsKey : number ;
361+ skippedValidators : number ;
362+ } > {
359363 const iface = new ethers . Interface ( ConsensusAbi . abi ) ;
360364
361365 this . logger . info ( `seeding ${ this . #data. validators . length } validators` ) ;
362366
363367 const stats = {
364- importedValidators : 0 ,
368+ importedValidatorsWithBlsKey : 0 ,
369+ importedValidatorsWithoutBlsKey : 0 ,
365370 skippedValidators : 0 ,
366371 } ;
367372
@@ -371,18 +376,16 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
371376 if ( ! validator . blsPublicKey ) {
372377 if ( ! options . mockFakeValidatorBlsKeys ) {
373378 this . logger . info (
374- `skipping legacy delegate ${ validator . arkAddress } (${ validator . username } ) without registered blsPublicKey` ,
379+ `importing legacy delegate ${ validator . arkAddress } (${ validator . username } ) without registered blsPublicKey` ,
375380 ) ;
376- stats . skippedValidators ++ ;
381+ stats . importedValidatorsWithoutBlsKey ++ ;
382+ } else {
383+ const entropy = sha256 ( Buffer . from ( validator . username , "utf8" ) ) . slice ( 2 , 34 ) ;
384+ const mnemonic = entropyToMnemonic ( Buffer . from ( entropy , "hex" ) ) ;
377385
378- continue ;
386+ const consensusKeyPair = await this . consensusKeyPairFactory . fromMnemonic ( mnemonic ) ;
387+ validator . blsPublicKey = consensusKeyPair . publicKey ;
379388 }
380-
381- const entropy = sha256 ( Buffer . from ( validator . username , "utf8" ) ) . slice ( 2 , 34 ) ;
382- const mnemonic = entropyToMnemonic ( Buffer . from ( entropy , "hex" ) ) ;
383-
384- const consensusKeyPair = await this . consensusKeyPairFactory . fromMnemonic ( mnemonic ) ;
385- validator . blsPublicKey = consensusKeyPair . publicKey ;
386389 } else {
387390 if ( ! ( await this . consensusPublicKeyFactory . verify ( validator . blsPublicKey ) ) ) {
388391 this . logger . info (
@@ -391,14 +394,14 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
391394 stats . skippedValidators ++ ;
392395 continue ;
393396 }
394- }
395397
396- assert . defined < string > ( validator . blsPublicKey ) ;
398+ stats . importedValidatorsWithBlsKey ++ ;
399+ }
397400
398401 const data = iface
399402 . encodeFunctionData ( "addValidator" , [
400403 validator . ethAddress ,
401- Buffer . from ( validator . blsPublicKey , "hex" ) ,
404+ validator . blsPublicKey ? Buffer . from ( validator . blsPublicKey , "hex" ) : Buffer . alloc ( 0 ) ,
402405 validator . isResigned ,
403406 ] )
404407 . slice ( 2 ) ;
@@ -414,8 +417,6 @@ export class Importer implements Contracts.Snapshot.LegacyImporter {
414417 if ( ! result . receipt . status ) {
415418 throw new Error ( "failed to add validator" ) ;
416419 }
417-
418- stats . importedValidators ++ ;
419420 }
420421
421422 return stats ;
0 commit comments