@@ -304,7 +304,7 @@ func NewBlockchain(cfg config.Config, opts ...Option) Blockchain {
304
304
if err != nil {
305
305
log .L ().Panic ("Failed to get block producer address." , zap .Error (err ))
306
306
}
307
- chain .validator = & validator {sf : chain .sf , validatorAddr : producerAddress ( cfg ).String ()}
307
+ chain .validator = & validator {sf : chain .sf , validatorAddr : cfg . ProducerAddress ( ).String ()}
308
308
309
309
if chain .dao != nil {
310
310
chain .lifecycle .Add (chain .dao )
@@ -727,14 +727,14 @@ func (bc *blockchain) MintNewBlock(
727
727
SetHeight (newblockHeight ).
728
728
SetTimeStamp (timestamp ).
729
729
AddActions (actions ... ).
730
- Build (producerAddr , producerPubKey )
730
+ Build (producerPubKey )
731
731
732
732
blk , err := block .NewBuilder (ra ).
733
733
SetPrevBlockHash (bc .tipHash ).
734
734
SetDeltaStateDigest (ws .Digest ()).
735
735
SetReceipts (rc ).
736
736
SetReceiptRoot (calculateReceiptRoot (rc )).
737
- SignAndBuild (producerPubKey , producerPriKey )
737
+ SignAndBuild (producerPriKey )
738
738
if err != nil {
739
739
return nil , errors .Wrapf (err , "failed to create block" )
740
740
}
@@ -951,7 +951,7 @@ func (bc *blockchain) startEmptyBlockchain() error {
951
951
ws factory.WorkingSet
952
952
err error
953
953
)
954
- pk , sk , addr , err := bc .genesisProducer ()
954
+ pk , sk , _ , err := bc .genesisProducer ()
955
955
if err != nil {
956
956
return errors .Wrap (err , "failed to get the key and address of producer" )
957
957
}
@@ -973,7 +973,7 @@ func (bc *blockchain) startEmptyBlockchain() error {
973
973
SetHeight (0 ).
974
974
SetTimeStamp (Gen .Timestamp ).
975
975
AddActions (acts ... ).
976
- Build (addr , pk )
976
+ Build (pk )
977
977
// run execution and update state trie root hash
978
978
receipts , err := bc .runActions (racts , ws )
979
979
if err != nil {
@@ -985,18 +985,18 @@ func (bc *blockchain) startEmptyBlockchain() error {
985
985
SetDeltaStateDigest (ws .Digest ()).
986
986
SetReceipts (receipts ).
987
987
SetReceiptRoot (calculateReceiptRoot (receipts )).
988
- SignAndBuild (pk , sk )
988
+ SignAndBuild (sk )
989
989
if err != nil {
990
990
return errors .Wrapf (err , "Failed to create block" )
991
991
}
992
992
} else {
993
993
racts := block .NewRunnableActionsBuilder ().
994
994
SetHeight (0 ).
995
995
SetTimeStamp (Gen .Timestamp ).
996
- Build (addr , pk )
996
+ Build (pk )
997
997
genesis , err = block .NewBuilder (racts ).
998
998
SetPrevBlockHash (hash .ZeroHash256 ).
999
- SignAndBuild (pk , sk )
999
+ SignAndBuild (sk )
1000
1000
if err != nil {
1001
1001
return errors .Wrapf (err , "Failed to create block" )
1002
1002
}
@@ -1139,7 +1139,8 @@ func (bc *blockchain) runActions(
1139
1139
}
1140
1140
gasLimit := bc .config .Genesis .BlockGasLimit
1141
1141
// update state factory
1142
- producer , err := address .FromString (acts .BlockProducerAddr ())
1142
+ pkHash := keypair .HashPubKey (acts .BlockProducerPubKey ())
1143
+ producer , err := address .FromBytes (pkHash [:])
1143
1144
if err != nil {
1144
1145
return nil , err
1145
1146
}
@@ -1321,10 +1322,7 @@ func (bc *blockchain) createPutPollResultAction(height uint64) (skip bool, se ac
1321
1322
default :
1322
1323
return
1323
1324
}
1324
- _ , sk , err := bc .config .KeyPair ()
1325
- if err != nil {
1326
- log .L ().Panic ("Failed to get block producer private key." , zap .Error (err ))
1327
- }
1325
+ sk := bc .config .ProducerPrivateKey ()
1328
1326
nonce := uint64 (0 )
1329
1327
pollAction := action .NewPutPollResult (nonce , nextEpochHeight , l )
1330
1328
builder := action.EnvelopeBuilder {}
@@ -1402,7 +1400,7 @@ func (bc *blockchain) refreshStateDB() error {
1402
1400
}
1403
1401
1404
1402
func (bc * blockchain ) buildStateInGenesis () error {
1405
- pk , _ , addr , err := bc .genesisProducer ()
1403
+ pk , _ , _ , err := bc .genesisProducer ()
1406
1404
if err != nil {
1407
1405
return errors .Wrap (err , "failed to get the key and address of producer" )
1408
1406
}
@@ -1415,7 +1413,7 @@ func (bc *blockchain) buildStateInGenesis() error {
1415
1413
SetHeight (0 ).
1416
1414
SetTimeStamp (Gen .Timestamp ).
1417
1415
AddActions (acts ... ).
1418
- Build (addr , pk )
1416
+ Build (pk )
1419
1417
// run execution and update state trie root hash
1420
1418
if _ , err := bc .runActions (racts , ws ); err != nil {
1421
1419
return errors .Wrap (err , "failed to update state changes in Genesis block" )
@@ -1439,10 +1437,7 @@ func (bc *blockchain) createGrantRewardAction(rewardType int) (action.SealedEnve
1439
1437
SetGasLimit (grant .GasLimit ()).
1440
1438
SetAction (& grant ).
1441
1439
Build ()
1442
- _ , sk , err := bc .config .KeyPair ()
1443
- if err != nil {
1444
- log .L ().Panic ("Failed to get block producer private key." , zap .Error (err ))
1445
- }
1440
+ sk := bc .config .ProducerPrivateKey ()
1446
1441
return action .Sign (envelope , sk )
1447
1442
}
1448
1443
@@ -1550,16 +1545,3 @@ func calculateReceiptRoot(receipts []*action.Receipt) hash.Hash256 {
1550
1545
res := crypto .NewMerkleTree (h ).HashTree ()
1551
1546
return res
1552
1547
}
1553
-
1554
- func producerAddress (cfg config.Config ) address.Address {
1555
- pubKey , _ , err := cfg .KeyPair ()
1556
- if err != nil {
1557
- log .L ().Panic ("Failed to get block producer public key." , zap .Error (err ))
1558
- }
1559
- pkHash := keypair .HashPubKey (pubKey )
1560
- address , err := address .FromBytes (pkHash [:])
1561
- if err != nil {
1562
- log .L ().Panic ("Failed to get block producer address." , zap .Error (err ))
1563
- }
1564
- return address
1565
- }
0 commit comments