mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
remove debug info
This commit is contained in:
parent
2b7010d51f
commit
87896dcdf9
3 changed files with 1 additions and 71 deletions
|
|
@ -1,13 +1,7 @@
|
||||||
package contracts
|
package contracts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
blockSignerContract "github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
@ -17,13 +11,9 @@ var (
|
||||||
"blockSigners": 0,
|
"blockSigners": 0,
|
||||||
"blocks": 1,
|
"blocks": 1,
|
||||||
}
|
}
|
||||||
ParsedBlockSignerABI, _ = abi.JSON(strings.NewReader(blockSignerContract.BlockSignerABI))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSigners(statedb *state.StateDB, block *types.Block) []common.Address {
|
func GetSigners(statedb *state.StateDB, block *types.Block) []common.Address {
|
||||||
methodName := "getSigners"
|
|
||||||
fmt.Printf("---%s---\n", methodName)
|
|
||||||
start := time.Now()
|
|
||||||
slot := slotBlockSignerMapping["blockSigners"]
|
slot := slotBlockSignerMapping["blockSigners"]
|
||||||
keys := []common.Hash{}
|
keys := []common.Hash{}
|
||||||
keyArrSlot := getLocMappingAtKey(block.Hash(), slot)
|
keyArrSlot := getLocMappingAtKey(block.Hash(), slot)
|
||||||
|
|
@ -37,10 +27,7 @@ func GetSigners(statedb *state.StateDB, block *types.Block) []common.Address {
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
ret := statedb.GetState(common.HexToAddress(common.BlockSigners), key)
|
ret := statedb.GetState(common.HexToAddress(common.BlockSigners), key)
|
||||||
rets = append(rets, common.HexToAddress(ret.Hex()))
|
rets = append(rets, common.HexToAddress(ret.Hex()))
|
||||||
fmt.Printf("%v\n", common.HexToAddress(ret.Hex()).Hex())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
package contracts
|
package contracts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize/contract"
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -16,17 +10,12 @@ var (
|
||||||
"randomSecret": 0,
|
"randomSecret": 0,
|
||||||
"randomOpening": 1,
|
"randomOpening": 1,
|
||||||
}
|
}
|
||||||
ParsedRandomizeABI, _ = abi.JSON(strings.NewReader(randomizeContract.XDCRandomizeABI))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetSecret(statedb *state.StateDB, address common.Address) [][32]byte {
|
func GetSecret(statedb *state.StateDB, address common.Address) [][32]byte {
|
||||||
start := time.Now()
|
|
||||||
fmt.Printf("--------GetSecret---------\n")
|
|
||||||
|
|
||||||
slot := slotRandomizeMapping["randomSecret"]
|
slot := slotRandomizeMapping["randomSecret"]
|
||||||
locSecret := getLocMappingAtKey(address.Hash(), slot)
|
locSecret := getLocMappingAtKey(address.Hash(), slot)
|
||||||
arrLength := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locSecret))
|
arrLength := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locSecret))
|
||||||
fmt.Printf("Secret length: %v\n", arrLength.Hex())
|
|
||||||
keys := []common.Hash{}
|
keys := []common.Hash{}
|
||||||
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
||||||
key := getLocDynamicArrAtElement(common.BigToHash(locSecret), i, 1)
|
key := getLocDynamicArrAtElement(common.BigToHash(locSecret), i, 1)
|
||||||
|
|
@ -36,23 +25,13 @@ func GetSecret(statedb *state.StateDB, address common.Address) [][32]byte {
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), key)
|
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), key)
|
||||||
rets = append(rets, ret)
|
rets = append(rets, ret)
|
||||||
fmt.Printf("ret hex: %v - ret byte: %v\n", ret.Hex(), ret.Bytes())
|
|
||||||
}
|
}
|
||||||
elapsed := time.Since(start)
|
|
||||||
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOpening(statedb *state.StateDB, address common.Address) [32]byte {
|
func GetOpening(statedb *state.StateDB, address common.Address) [32]byte {
|
||||||
start := time.Now()
|
|
||||||
fmt.Printf("--------GetOpening---------\n")
|
|
||||||
|
|
||||||
slot := slotRandomizeMapping["randomOpening"]
|
slot := slotRandomizeMapping["randomOpening"]
|
||||||
locOpening := getLocMappingAtKey(address.Hash(), slot)
|
locOpening := getLocMappingAtKey(address.Hash(), slot)
|
||||||
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locOpening))
|
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locOpening))
|
||||||
fmt.Printf("ret hex: %v - ret byte: %v\n", ret.Hex(), ret.Bytes())
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
@ -1,20 +1,15 @@
|
||||||
package contracts
|
package contracts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi"
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
validatorContract "github.com/ethereum/go-ethereum/contracts/validator/contract"
|
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ParsedValidatorABI, _ = abi.JSON(strings.NewReader(validatorContract.XDCValidatorABI))
|
|
||||||
slotValidatorMapping = map[string]uint64{
|
slotValidatorMapping = map[string]uint64{
|
||||||
"withdrawsState": 0,
|
"withdrawsState": 0,
|
||||||
"validatorsState": 1,
|
"validatorsState": 1,
|
||||||
|
|
@ -29,12 +24,10 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetCandidates(statedb *state.StateDB, parsed abi.ABI) []common.Address {
|
func GetCandidates(statedb *state.StateDB) []common.Address {
|
||||||
start := time.Now()
|
|
||||||
slot := slotValidatorMapping["candidates"]
|
slot := slotValidatorMapping["candidates"]
|
||||||
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
|
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
|
||||||
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), slotHash)
|
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), slotHash)
|
||||||
fmt.Printf("Candidates length: %v\n", arrLength.Hex())
|
|
||||||
keys := []common.Hash{}
|
keys := []common.Hash{}
|
||||||
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
||||||
key := getLocDynamicArrAtElement(slotHash, i, 1)
|
key := getLocDynamicArrAtElement(slotHash, i, 1)
|
||||||
|
|
@ -44,53 +37,33 @@ func GetCandidates(statedb *state.StateDB, parsed abi.ABI) []common.Address {
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), key)
|
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), key)
|
||||||
rets = append(rets, common.HexToAddress(ret.Hex()))
|
rets = append(rets, common.HexToAddress(ret.Hex()))
|
||||||
fmt.Printf("%v\n", common.HexToAddress(ret.Hex()).Hex())
|
|
||||||
}
|
}
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCandidateOwner(statedb *state.StateDB, candidate common.Address) common.Address {
|
func GetCandidateOwner(statedb *state.StateDB, candidate common.Address) common.Address {
|
||||||
start := time.Now()
|
|
||||||
fmt.Printf("--------GetCandidateOwner---------\n")
|
|
||||||
|
|
||||||
slot := slotValidatorMapping["validatorsState"]
|
slot := slotValidatorMapping["validatorsState"]
|
||||||
// validatorsState[_candidate].owner;
|
// validatorsState[_candidate].owner;
|
||||||
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
||||||
locCandidateOwner := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(0)))
|
locCandidateOwner := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(0)))
|
||||||
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateOwner))
|
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateOwner))
|
||||||
fmt.Printf("ret: %v\n", common.HexToAddress(ret.Hex()).Hex())
|
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return common.HexToAddress(ret.Hex())
|
return common.HexToAddress(ret.Hex())
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCandidateCap(statedb *state.StateDB, parsed abi.ABI, candidate common.Address) string {
|
func GetCandidateCap(statedb *state.StateDB, parsed abi.ABI, candidate common.Address) string {
|
||||||
start := time.Now()
|
|
||||||
|
|
||||||
slot := slotValidatorMapping["validatorsState"]
|
slot := slotValidatorMapping["validatorsState"]
|
||||||
// validatorsState[_candidate].cap;
|
// validatorsState[_candidate].cap;
|
||||||
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
||||||
locCandidateCap := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(1)))
|
locCandidateCap := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(1)))
|
||||||
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateCap))
|
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateCap))
|
||||||
fmt.Printf("ret hex: %v\n", ret.Hex())
|
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return ret.Hex()
|
return ret.Hex()
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Address {
|
func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Address {
|
||||||
start := time.Now()
|
|
||||||
fmt.Printf("--------GetVoters---------\n")
|
|
||||||
|
|
||||||
//mapping(address => address[]) voters;
|
//mapping(address => address[]) voters;
|
||||||
slot := slotValidatorMapping["voters"]
|
slot := slotValidatorMapping["voters"]
|
||||||
locVoters := getLocMappingAtKey(candidate.Hash(), slot)
|
locVoters := getLocMappingAtKey(candidate.Hash(), slot)
|
||||||
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locVoters))
|
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locVoters))
|
||||||
fmt.Printf("Voters length: %v\n", arrLength.Hex())
|
|
||||||
keys := []common.Hash{}
|
keys := []common.Hash{}
|
||||||
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
|
||||||
key := getLocDynamicArrAtElement(common.BigToHash(locVoters), i, 1)
|
key := getLocDynamicArrAtElement(common.BigToHash(locVoters), i, 1)
|
||||||
|
|
@ -100,25 +73,16 @@ func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Addres
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), key)
|
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), key)
|
||||||
rets = append(rets, common.HexToAddress(ret.Hex()))
|
rets = append(rets, common.HexToAddress(ret.Hex()))
|
||||||
fmt.Printf("%v\n", common.HexToAddress(ret.Hex()).Hex())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVoterCap(state *state.StateDB, candidate, voter common.Address) *big.Int {
|
func GetVoterCap(state *state.StateDB, candidate, voter common.Address) *big.Int {
|
||||||
//validatorsState[_candidate].voters[_voter]
|
|
||||||
start := time.Now()
|
|
||||||
fmt.Printf("--------GetVoterCap---------\n")
|
|
||||||
slot := slotValidatorMapping["validatorsState"]
|
slot := slotValidatorMapping["validatorsState"]
|
||||||
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
||||||
locCandidateVoters := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(2)))
|
locCandidateVoters := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(2)))
|
||||||
retByte := crypto.Keccak256(voter.Hash().Bytes(), common.BigToHash(locCandidateVoters).Bytes())
|
retByte := crypto.Keccak256(voter.Hash().Bytes(), common.BigToHash(locCandidateVoters).Bytes())
|
||||||
ret := state.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BytesToHash(retByte))
|
ret := state.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BytesToHash(retByte))
|
||||||
fmt.Printf("voter: %v - cap: %v\n", voter.Hex(), ret.Big().String())
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
|
||||||
return ret.Big()
|
return ret.Big()
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue