@ -666,6 +666,11 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
utils . Logger ( ) . Warn ( ) . Msgf ( "Blacklist setup error: %s" , err . Error ( ) )
utils . Logger ( ) . Warn ( ) . Msgf ( "Blacklist setup error: %s" , err . Error ( ) )
}
}
localAccounts , err := setupLocalAccounts ( hc , blacklist )
if err != nil {
utils . Logger ( ) . Warn ( ) . Msgf ( "local accounts setup error: %s" , err . Error ( ) )
}
// Current node.
// Current node.
var chainDBFactory shardchain . DBFactory
var chainDBFactory shardchain . DBFactory
if hc . ShardData . EnableShardData {
if hc . ShardData . EnableShardData {
@ -680,7 +685,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi
chainDBFactory = & shardchain . LDBFactory { RootDir : nodeConfig . DBDir }
chainDBFactory = & shardchain . LDBFactory { RootDir : nodeConfig . DBDir }
}
}
currentNode := node . New ( myHost , currentConsensus , chainDBFactory , blacklist , nodeConfig . ArchiveModes ( ) , & hc )
currentNode := node . New ( myHost , currentConsensus , chainDBFactory , blacklist , localAccounts , nodeConfig . ArchiveModes ( ) , & hc )
if hc . Legacy != nil && hc . Legacy . TPBroadcastInvalidTxn != nil {
if hc . Legacy != nil && hc . Legacy . TPBroadcastInvalidTxn != nil {
currentNode . BroadcastInvalidTx = * hc . Legacy . TPBroadcastInvalidTxn
currentNode . BroadcastInvalidTx = * hc . Legacy . TPBroadcastInvalidTxn
@ -845,6 +850,52 @@ func setupBlacklist(hc harmonyconfig.HarmonyConfig) (map[ethCommon.Address]struc
return addrMap , nil
return addrMap , nil
}
}
func setupLocalAccounts ( hc harmonyconfig . HarmonyConfig , blacklist map [ ethCommon . Address ] struct { } ) ( [ ] ethCommon . Address , error ) {
file := hc . TxPool . LocalAccountsFile
// check if file exist
var fileData string
if _ , err := os . Stat ( file ) ; err == nil {
b , err := ioutil . ReadFile ( file )
if err != nil {
return nil , err
}
fileData = string ( b )
} else if errors . Is ( err , os . ErrNotExist ) {
// file path does not exist
return [ ] ethCommon . Address { } , nil
} else {
// some other errors happened
return nil , err
}
localAccounts := make ( map [ ethCommon . Address ] struct { } )
lines := strings . Split ( fileData , "\n" )
for _ , line := range lines {
if len ( line ) != 0 { // the file may have trailing empty string line
trimmedLine := strings . TrimSpace ( line )
if strings . HasPrefix ( trimmedLine , "#" ) { //check the line is not commented
continue
}
addr , err := common . Bech32ToAddress ( trimmedLine )
if err != nil {
return nil , err
}
// skip the blacklisted addresses
if _ , exists := blacklist [ addr ] ; exists {
utils . Logger ( ) . Warn ( ) . Msgf ( "local account with address %s is blacklisted" , addr . String ( ) )
continue
}
localAccounts [ addr ] = struct { } { }
}
}
uniqueAddresses := make ( [ ] ethCommon . Address , 0 , len ( localAccounts ) )
for addr := range localAccounts {
uniqueAddresses = append ( uniqueAddresses , addr )
}
return uniqueAddresses , nil
}
func listenOSSigAndShutDown ( node * node . Node ) {
func listenOSSigAndShutDown ( node * node . Node ) {
// Prepare for graceful shutdown from os signals
// Prepare for graceful shutdown from os signals
osSignal := make ( chan os . Signal , 1 )
osSignal := make ( chan os . Signal , 1 )