@@ -659,7 +659,7 @@ func (p *Parlia) Finalize(chain consensus.ChainReader, header *types.Header, sta
659
659
// No block rewards in PoA, so the state remains as is and uncles are dropped
660
660
cx := chainContext {Chain : chain , parlia : p }
661
661
if header .Number .Cmp (common .Big1 ) == 0 {
662
- err := p .initContract (state , header , cx , txs , receipts , systemTxs , usedGas )
662
+ err := p .initContract (state , header , cx , txs , receipts , systemTxs , usedGas , false )
663
663
if err != nil {
664
664
log .Error ("init contract failed" )
665
665
}
@@ -680,14 +680,14 @@ func (p *Parlia) Finalize(chain consensus.ChainReader, header *types.Header, sta
680
680
}
681
681
if ! signedRecently {
682
682
log .Info ("slash validator" , "block hash" , header .Hash (), "address" , spoiledVal )
683
- err = p .slash (spoiledVal , state , header , cx , txs , receipts , systemTxs , usedGas )
683
+ err = p .slash (spoiledVal , state , header , cx , txs , receipts , systemTxs , usedGas , false )
684
684
if err != nil {
685
685
panic (err )
686
686
}
687
687
}
688
688
}
689
689
val := header .Coinbase
690
- err := p .distributeIncoming (val , state , header , cx , txs , receipts , systemTxs , usedGas )
690
+ err := p .distributeIncoming (val , state , header , cx , txs , receipts , systemTxs , usedGas , false )
691
691
if err != nil {
692
692
panic (err )
693
693
}
@@ -712,7 +712,7 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types.
712
712
receipts = make ([]* types.Receipt , 0 )
713
713
}
714
714
if header .Number .Cmp (common .Big1 ) == 0 {
715
- err := p .initContract (state , header , cx , & txs , & receipts , nil , & header .GasUsed )
715
+ err := p .initContract (state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
716
716
if err != nil {
717
717
log .Error ("init contract failed" )
718
718
}
@@ -732,13 +732,13 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types.
732
732
}
733
733
}
734
734
if ! signedRecently {
735
- err = p .slash (spoiledVal , state , header , cx , & txs , & receipts , nil , & header .GasUsed )
735
+ err = p .slash (spoiledVal , state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
736
736
if err != nil {
737
737
panic (err )
738
738
}
739
739
}
740
740
}
741
- err := p .distributeIncoming (p .val , state , header , cx , & txs , & receipts , nil , & header .GasUsed )
741
+ err := p .distributeIncoming (p .val , state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
742
742
if err != nil {
743
743
panic (err )
744
744
}
@@ -929,7 +929,7 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address,
929
929
930
930
// slash spoiled validators
931
931
func (p * Parlia ) distributeIncoming (val common.Address , state * state.StateDB , header * types.Header , chain core.ChainContext ,
932
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
932
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ) error {
933
933
coinbase := header .Coinbase
934
934
balance := state .GetBalance (consensus .SystemAddress )
935
935
if balance .Cmp (common .Big0 ) <= 0 {
@@ -943,7 +943,7 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
943
943
var rewards = new (big.Int )
944
944
rewards = rewards .Rsh (balance , systemRewardPercent )
945
945
if rewards .Cmp (common .Big0 ) > 0 {
946
- err := p .distributeToSystem (rewards , state , header , chain , txs , receipts , receivedTxs , usedGas )
946
+ err := p .distributeToSystem (rewards , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
947
947
if err != nil {
948
948
return err
949
949
}
@@ -952,12 +952,12 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
952
952
}
953
953
}
954
954
log .Info ("distribute to validator contract" , "block hash" , header .Hash (), "amount" , balance )
955
- return p .distributeToValidator (balance , val , state , header , chain , txs , receipts , receivedTxs , usedGas )
955
+ return p .distributeToValidator (balance , val , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
956
956
}
957
957
958
958
// slash spoiled validators
959
959
func (p * Parlia ) slash (spoiledVal common.Address , state * state.StateDB , header * types.Header , chain core.ChainContext ,
960
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
960
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ) error {
961
961
// method
962
962
method := "slash"
963
963
@@ -972,12 +972,12 @@ func (p *Parlia) slash(spoiledVal common.Address, state *state.StateDB, header *
972
972
// get system message
973
973
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (SlashContract ), data , common .Big0 )
974
974
// apply message
975
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
975
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
976
976
}
977
977
978
978
// init contract
979
979
func (p * Parlia ) initContract (state * state.StateDB , header * types.Header , chain core.ChainContext ,
980
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
980
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ) error {
981
981
// method
982
982
method := "init"
983
983
// contracts
@@ -992,7 +992,7 @@ func (p *Parlia) initContract(state *state.StateDB, header *types.Header, chain
992
992
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (c ), data , common .Big0 )
993
993
// apply message
994
994
log .Info ("init contract" , "block hash" , header .Hash (), "contract" , c )
995
- err = p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
995
+ err = p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
996
996
if err != nil {
997
997
return err
998
998
}
@@ -1001,17 +1001,17 @@ func (p *Parlia) initContract(state *state.StateDB, header *types.Header, chain
1001
1001
}
1002
1002
1003
1003
func (p * Parlia ) distributeToSystem (amount * big.Int , state * state.StateDB , header * types.Header , chain core.ChainContext ,
1004
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
1004
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ) error {
1005
1005
// get system message
1006
1006
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (SystemRewardContract ), nil , amount )
1007
1007
// apply message
1008
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
1008
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
1009
1009
}
1010
1010
1011
1011
// slash spoiled validators
1012
1012
func (p * Parlia ) distributeToValidator (amount * big.Int , validator common.Address ,
1013
1013
state * state.StateDB , header * types.Header , chain core.ChainContext ,
1014
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
1014
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ) error {
1015
1015
// method
1016
1016
method := "deposit"
1017
1017
@@ -1026,7 +1026,7 @@ func (p *Parlia) distributeToValidator(amount *big.Int, validator common.Address
1026
1026
// get system message
1027
1027
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (ValidatorContract ), data , amount )
1028
1028
// apply message
1029
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
1029
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mining )
1030
1030
}
1031
1031
1032
1032
// get system message
@@ -1049,13 +1049,13 @@ func (p *Parlia) applyTransaction(
1049
1049
header * types.Header ,
1050
1050
chainContext core.ChainContext ,
1051
1051
txs * []* types.Transaction , receipts * []* types.Receipt ,
1052
- receivedTxs * []* types.Transaction , usedGas * uint64 ,
1052
+ receivedTxs * []* types.Transaction , usedGas * uint64 , mining bool ,
1053
1053
) (err error ) {
1054
1054
nonce := state .GetNonce (msg .From ())
1055
1055
expectedTx := types .NewTransaction (nonce , * msg .To (), msg .Value (), msg .Gas (), msg .GasPrice (), msg .Data ())
1056
1056
expectedHash := p .signer .Hash (expectedTx )
1057
1057
1058
- if msg .From () == p .val {
1058
+ if msg .From () == p .val && mining {
1059
1059
expectedTx , err = p .signTxFn (accounts.Account {Address : msg .From ()}, expectedTx , p .chainConfig .ChainID )
1060
1060
if err != nil {
1061
1061
return err
0 commit comments