@@ -653,7 +653,7 @@ func (p *Parlia) Finalize(chain consensus.ChainReader, header *types.Header, sta
653
653
// No block rewards in PoA, so the state remains as is and uncles are dropped
654
654
cx := chainContext {Chain : chain , parlia : p }
655
655
if header .Number .Cmp (common .Big1 ) == 0 {
656
- err := p .initContract (state , header , cx , txs , receipts , systemTxs , usedGas )
656
+ err := p .initContract (state , header , cx , txs , receipts , systemTxs , usedGas , false )
657
657
if err != nil {
658
658
log .Error ("init contract failed" )
659
659
}
@@ -674,14 +674,14 @@ func (p *Parlia) Finalize(chain consensus.ChainReader, header *types.Header, sta
674
674
}
675
675
if ! signedRecently {
676
676
log .Info ("slash validator" , "block hash" , header .Hash (), "address" , spoiledVal )
677
- err = p .slash (spoiledVal , state , header , cx , txs , receipts , systemTxs , usedGas )
677
+ err = p .slash (spoiledVal , state , header , cx , txs , receipts , systemTxs , usedGas , false )
678
678
if err != nil {
679
679
panic (err )
680
680
}
681
681
}
682
682
}
683
683
val := header .Coinbase
684
- err := p .distributeIncoming (val , state , header , cx , txs , receipts , systemTxs , usedGas )
684
+ err := p .distributeIncoming (val , state , header , cx , txs , receipts , systemTxs , usedGas , false )
685
685
if err != nil {
686
686
panic (err )
687
687
}
@@ -706,7 +706,7 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types.
706
706
receipts = make ([]* types.Receipt , 0 )
707
707
}
708
708
if header .Number .Cmp (common .Big1 ) == 0 {
709
- err := p .initContract (state , header , cx , & txs , & receipts , nil , & header .GasUsed )
709
+ err := p .initContract (state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
710
710
if err != nil {
711
711
log .Error ("init contract failed" )
712
712
}
@@ -726,13 +726,13 @@ func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types.
726
726
}
727
727
}
728
728
if ! signedRecently {
729
- err = p .slash (spoiledVal , state , header , cx , & txs , & receipts , nil , & header .GasUsed )
729
+ err = p .slash (spoiledVal , state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
730
730
if err != nil {
731
731
panic (err )
732
732
}
733
733
}
734
734
}
735
- err := p .distributeIncoming (p .val , state , header , cx , & txs , & receipts , nil , & header .GasUsed )
735
+ err := p .distributeIncoming (p .val , state , header , cx , & txs , & receipts , nil , & header .GasUsed , true )
736
736
if err != nil {
737
737
panic (err )
738
738
}
@@ -923,7 +923,7 @@ func (p *Parlia) getCurrentValidators(blockHash common.Hash) ([]common.Address,
923
923
924
924
// slash spoiled validators
925
925
func (p * Parlia ) distributeIncoming (val common.Address , state * state.StateDB , header * types.Header , chain core.ChainContext ,
926
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
926
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ) error {
927
927
coinbase := header .Coinbase
928
928
balance := state .GetBalance (consensus .SystemAddress )
929
929
if balance .Cmp (common .Big0 ) <= 0 {
@@ -937,7 +937,7 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
937
937
var rewards = new (big.Int )
938
938
rewards = rewards .Rsh (balance , systemRewardPercent )
939
939
if rewards .Cmp (common .Big0 ) > 0 {
940
- err := p .distributeToSystem (rewards , state , header , chain , txs , receipts , receivedTxs , usedGas )
940
+ err := p .distributeToSystem (rewards , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
941
941
if err != nil {
942
942
return err
943
943
}
@@ -946,12 +946,12 @@ func (p *Parlia) distributeIncoming(val common.Address, state *state.StateDB, he
946
946
}
947
947
}
948
948
log .Info ("distribute to validator contract" , "block hash" , header .Hash (), "amount" , balance )
949
- return p .distributeToValidator (balance , val , state , header , chain , txs , receipts , receivedTxs , usedGas )
949
+ return p .distributeToValidator (balance , val , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
950
950
}
951
951
952
952
// slash spoiled validators
953
953
func (p * Parlia ) slash (spoiledVal common.Address , state * state.StateDB , header * types.Header , chain core.ChainContext ,
954
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
954
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ) error {
955
955
// method
956
956
method := "slash"
957
957
@@ -966,12 +966,12 @@ func (p *Parlia) slash(spoiledVal common.Address, state *state.StateDB, header *
966
966
// get system message
967
967
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (SlashContract ), data , common .Big0 )
968
968
// apply message
969
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
969
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
970
970
}
971
971
972
972
// init contract
973
973
func (p * Parlia ) initContract (state * state.StateDB , header * types.Header , chain core.ChainContext ,
974
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
974
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ) error {
975
975
// method
976
976
method := "init"
977
977
// contracts
@@ -986,7 +986,7 @@ func (p *Parlia) initContract(state *state.StateDB, header *types.Header, chain
986
986
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (c ), data , common .Big0 )
987
987
// apply message
988
988
log .Info ("init contract" , "block hash" , header .Hash (), "contract" , c )
989
- err = p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
989
+ err = p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
990
990
if err != nil {
991
991
return err
992
992
}
@@ -995,17 +995,17 @@ func (p *Parlia) initContract(state *state.StateDB, header *types.Header, chain
995
995
}
996
996
997
997
func (p * Parlia ) distributeToSystem (amount * big.Int , state * state.StateDB , header * types.Header , chain core.ChainContext ,
998
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
998
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ) error {
999
999
// get system message
1000
1000
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (SystemRewardContract ), nil , amount )
1001
1001
// apply message
1002
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
1002
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
1003
1003
}
1004
1004
1005
1005
// slash spoiled validators
1006
1006
func (p * Parlia ) distributeToValidator (amount * big.Int , validator common.Address ,
1007
1007
state * state.StateDB , header * types.Header , chain core.ChainContext ,
1008
- txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 ) error {
1008
+ txs * []* types.Transaction , receipts * []* types.Receipt , receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ) error {
1009
1009
// method
1010
1010
method := "deposit"
1011
1011
@@ -1020,7 +1020,7 @@ func (p *Parlia) distributeToValidator(amount *big.Int, validator common.Address
1020
1020
// get system message
1021
1021
msg := p .getSystemMessage (header .Coinbase , common .HexToAddress (ValidatorContract ), data , amount )
1022
1022
// apply message
1023
- return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas )
1023
+ return p .applyTransaction (msg , state , header , chain , txs , receipts , receivedTxs , usedGas , mine )
1024
1024
}
1025
1025
1026
1026
// get system message
@@ -1043,13 +1043,13 @@ func (p *Parlia) applyTransaction(
1043
1043
header * types.Header ,
1044
1044
chainContext core.ChainContext ,
1045
1045
txs * []* types.Transaction , receipts * []* types.Receipt ,
1046
- receivedTxs * []* types.Transaction , usedGas * uint64 ,
1046
+ receivedTxs * []* types.Transaction , usedGas * uint64 , mine bool ,
1047
1047
) (err error ) {
1048
1048
nonce := state .GetNonce (msg .From ())
1049
1049
expectedTx := types .NewTransaction (nonce , * msg .To (), msg .Value (), msg .Gas (), msg .GasPrice (), msg .Data ())
1050
1050
expectedHash := p .signer .Hash (expectedTx )
1051
1051
1052
- if msg .From () == p .val {
1052
+ if msg .From () == p .val && mine {
1053
1053
expectedTx , err = p .signTxFn (accounts.Account {Address : msg .From ()}, expectedTx , p .chainConfig .ChainID )
1054
1054
if err != nil {
1055
1055
return err
0 commit comments