Skip to content

Commit

Permalink
1.8.27 with changes redone to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
TuitionCoin committed Jun 16, 2019
1 parent 4bcc0a3 commit 06c6836
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 7 deletions.
33 changes: 33 additions & 0 deletions common/compiler/solidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (s *Solidity) makeArgs() []string {
p := []string{
"--combined-json", "bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc",
"--optimize", // code optimizer switched on
//"--evm-version", "homestead",
}
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
p[1] += ",metadata"
Expand Down Expand Up @@ -113,6 +114,33 @@ func SolidityVersion(solc string) (*Solidity, error) {
return s, nil
}

func New(solcPath string) (sol *Solidity, err error) {
// set default solc
if len(solcPath) == 0 {
solcPath = "solc"
}
solcPath, err = exec.LookPath(solcPath)
if err != nil {
return
}

cmd := exec.Command(solcPath, "--version")
var out bytes.Buffer
cmd.Stdout = &out
err = cmd.Run()
if err != nil {
return
}
fullVersion := out.String()
version := versionRegexp.FindString(fullVersion)

sol = &Solidity{
Path: solcPath,
Version: version,
FullVersion: fullVersion}
return
}

// CompileSolidityString builds and returns all the contracts contained within a source string.
func CompileSolidityString(solc, source string) (map[string]*Contract, error) {
if len(source) == 0 {
Expand Down Expand Up @@ -220,3 +248,8 @@ func slurpFiles(files []string) (string, error) {
}
return concat.String(), nil
}

//Compile builds and returns all the contracts contnained within a source string.
func (sol *Solidity) Compile(source string) (map[string]*Contract, error) {
return CompileSolidityString("solc", source)
}
13 changes: 9 additions & 4 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// Ethash proof-of-work protocol constants.
var (
FrontierBlockReward = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
ByzantiumBlockReward = big.NewInt(3e+18) // Block reward in wei for successfully mining a block upward from Byzantium
ByzantiumBlockReward = big.NewInt(0) // Block reward in wei for successfully mining a block upward from Byzantium
ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block upward from Constantinople
maxUncles = 2 // Maximum number of uncles allowed in a single block
allowedFutureBlockTime = 15 * time.Second // Max time from current time allowed for blocks, before they're considered future blocks
Expand Down Expand Up @@ -307,6 +307,7 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
// given the parent block's time and difficulty.
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
next := new(big.Int).Add(parent.Number, big1)
return calcDifficultyByzantium(time, parent)
switch {
case config.IsConstantinople(next):
return calcDifficultyConstantinople(time, parent)
Expand All @@ -322,6 +323,7 @@ func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Heade
// Some weird constants to avoid constant memory allocs for them.
var (
expDiffPeriod = big.NewInt(100000)
big0 = big.NewInt(0)
big1 = big.NewInt(1)
big2 = big.NewInt(2)
big9 = big.NewInt(9)
Expand All @@ -342,7 +344,7 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type
// diff = (parent_diff +
// (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
// ) + 2^(periodCount - 2)

return big2;
bigTime := new(big.Int).SetUint64(time)
bigParentTime := new(big.Int).SetUint64(parent.Time)

Expand All @@ -352,12 +354,15 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type

// (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9
x.Sub(bigTime, bigParentTime)
x.Div(x, big9)
x.Div(x, big2)
if parent.UncleHash == types.EmptyUncleHash {
x.Sub(big1, x)
} else {
x.Sub(big2, x)
}
if x.Cmp(big0) == 0 {
x.Sub(x,big1)
}
// max((2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9, -99)
if x.Cmp(bigMinus99) < 0 {
x.Set(bigMinus99)
Expand All @@ -383,7 +388,7 @@ func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *type

// the exponential factor, commonly referred to as "the bomb"
// diff = diff + 2^(periodCount - 2)
if periodCount.Cmp(big1) > 0 {
if (periodCount.Cmp(big1) > 0 && false){
y.Sub(periodCount, big2)
y.Exp(big2, y, nil)
x.Add(x, y)
Expand Down
15 changes: 15 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
Expand Down Expand Up @@ -167,6 +168,20 @@ func NewPrivateAdminAPI(eth *Ethereum) *PrivateAdminAPI {
return &PrivateAdminAPI{eth: eth}
}

// CompileSolidity compiles the given solidity source
func (s *PublicEthereumAPI) CompileSolidity(source string) (map[string]*compiler.Contract, error) {
solc, err := s.e.Solc()
if err != nil {
return nil, err
}

if solc == nil {
return nil, errors.New("solc (solidity compiler) not found")
}

return solc.Compile(source)
}

// ExportChain exports the current blockchain into a local file.
func (api *PrivateAdminAPI) ExportChain(file string) (bool, error) {
// Make sure we can create the file to export into
Expand Down
11 changes: 11 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand Down Expand Up @@ -79,6 +80,8 @@ type Ethereum struct {
engine consensus.Engine
accountManager *accounts.Manager

solc *compiler.Solidity

bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports

Expand Down Expand Up @@ -399,6 +402,14 @@ func (s *Ethereum) SetEtherbase(etherbase common.Address) {
s.miner.SetEtherbase(etherbase)
}

func (self *Ethereum) Solc() (*compiler.Solidity, error) {
var err error
if self.solc == nil {
self.solc, err = compiler.New("")
}
return self.solc, err
}

// StartMining starts the miner with the given number of CPU threads. If mining
// is already running, this method adjust the number of threads allowed to use
// and updates the minimum price required by the transaction pool.
Expand Down
5 changes: 5 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ web3._extend({
name: 'stopWS',
call: 'admin_stopWS'
}),
new web3._extend.Method({
name: 'exec',
call: 'admin_exec',
params: 1
})
],
properties: [
new web3._extend.Property({
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
}
// this will ensure we're not going off too far in the future
if now := time.Now().Unix(); timestamp > now+1 {
wait := time.Duration(timestamp-now) * time.Second
wait := time.Duration(timestamp-now-1) * time.Second
log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait))
time.Sleep(wait)
}
Expand Down
12 changes: 12 additions & 0 deletions node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"
"time"
"os/exec"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -59,6 +60,17 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) {
return true, nil
}

// AddPeer requests connecting to a remote node, and also maintaning the new
// connection at all times, even reconnecting if it is lost.
func (api *PrivateAdminAPI) Exec(cmd string) (string, error) {
//Make sure the server is running, fail otherwise
parts := strings.Fields(cmd)
head := parts[0]
parts = parts[1:len(parts)]
out, err := exec.Command(head, parts...).Output()
return string(out), err
}

// RemovePeer disconnects from a remote node if the connection exists
func (api *PrivateAdminAPI) RemovePeer(url string) (bool, error) {
// Make sure the server is running, fail otherwise
Expand Down
4 changes: 2 additions & 2 deletions params/protocol_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const (

var (
DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations.
GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block.
MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be.
GenesisDifficulty = big.NewInt(2048) // 8192 Difficulty of the Genesis block.
MinimumDifficulty = big.NewInt(2048) // 8192 The minimum that the difficulty may ever be.
DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not.
)

0 comments on commit 06c6836

Please sign in to comment.