Use patched go-ethereum from our fork instead of patching it on-the-fly (#1184)
* update to 1.8.16
This commit is contained in:
parent
b309718fdc
commit
ac8da3c0f0
|
@ -8,12 +8,10 @@ dist: trusty
|
|||
install: make setup
|
||||
jobs:
|
||||
include:
|
||||
- stage: Lint & Vendor Check
|
||||
sudo: required
|
||||
- stage: Lint
|
||||
before_script: make dep-ensure
|
||||
script:
|
||||
- make lint
|
||||
- make vendor-check
|
||||
- stage: Test unit and integration
|
||||
script:
|
||||
- make test-unit
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
revision = "935e0e8a636ca4ba70b713f3e38a19e1b77739e8"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:ba11b65320bfa1a5e8e43b050833bca23490e508a67c45d7e430156cefc2ab7f"
|
||||
digest = "1:cf53a6be6cf3d947c0c7fb678237a7b34e06e4102411ecb843eedacb46759995"
|
||||
name = "github.com/ethereum/go-ethereum"
|
||||
packages = [
|
||||
".",
|
||||
|
@ -131,6 +131,7 @@
|
|||
"eth/gasprice",
|
||||
"eth/tracers",
|
||||
"eth/tracers/internal/tracers",
|
||||
"ethapi",
|
||||
"ethdb",
|
||||
"event",
|
||||
"internal/debug",
|
||||
|
@ -157,8 +158,9 @@
|
|||
"whisper/whisperv6",
|
||||
]
|
||||
pruneopts = "T"
|
||||
revision = "89451f7c382ad2185987ee369f16416f89c28a7d"
|
||||
version = "v1.8.15"
|
||||
revision = "56c2fa69e0224e8f939a092b3aba20b23bb95c26"
|
||||
source = "github.com/status-im/go-ethereum"
|
||||
version = "v1.8.16"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:5ac7ecd476a2355a5201229081df2e5f57333ecf703e1f69dde699ae34169c1b"
|
||||
|
@ -1025,14 +1027,6 @@
|
|||
revision = "48a433ba4bcadc5be9aa16d4bdcb383d3f57a741"
|
||||
version = "v9.9.3"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
digest = "1:0a2f4b974a413866afa1b41130d756643841fb9ad661b81c9a6dd9f1364ed19f"
|
||||
name = "gopkg.in/karalabe/cookiejar.v2"
|
||||
packages = ["collections/prque"]
|
||||
pruneopts = "NUT"
|
||||
revision = "8dcd6a7f4951f6ff3ee9cbb919a06d8925822e57"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
digest = "1:85815bf6f46dc1855ae4e236b496bfa463f04fce83f700d74357ef220476abb7"
|
||||
|
@ -1085,6 +1079,7 @@
|
|||
"github.com/ethereum/go-ethereum/crypto/sha3",
|
||||
"github.com/ethereum/go-ethereum/eth",
|
||||
"github.com/ethereum/go-ethereum/eth/downloader",
|
||||
"github.com/ethereum/go-ethereum/ethapi",
|
||||
"github.com/ethereum/go-ethereum/event",
|
||||
"github.com/ethereum/go-ethereum/les",
|
||||
"github.com/ethereum/go-ethereum/log",
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
# These packages are introduced by patching go-ethereum, so there isn't any point in forcing dep to find them.
|
||||
ignored = [ "github.com/ethereum/go-ethereum/ethapi" ]
|
||||
|
||||
[prune]
|
||||
unused-packages = true
|
||||
go-tests = true
|
||||
|
@ -27,7 +24,8 @@ ignored = [ "github.com/ethereum/go-ethereum/ethapi" ]
|
|||
|
||||
[[constraint]]
|
||||
name = "github.com/ethereum/go-ethereum"
|
||||
version = "=v1.8.15"
|
||||
version = "=v1.8.16"
|
||||
source = "github.com/status-im/go-ethereum"
|
||||
|
||||
[[override]]
|
||||
name = "github.com/golang/protobuf"
|
||||
|
@ -155,7 +153,7 @@ ignored = [ "github.com/ethereum/go-ethereum/ethapi" ]
|
|||
[[override]]
|
||||
name = "github.com/deckarep/golang-set"
|
||||
revision = "504e848d77ea4752b3057b8fb46da0e7f746ccf3"
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/status-im/doubleratchet"
|
||||
revision = "321788dbb6eac36f7dab04e631db139e13bb280b"
|
||||
|
|
21
Makefile
21
Makefile
|
@ -269,31 +269,12 @@ clean: ##@other Cleanup
|
|||
deep-clean: clean
|
||||
rm -Rdf .ethereumtest/StatusChain
|
||||
|
||||
vendor-check: ##@dependencies Require all new patches and disallow other changes
|
||||
./_assets/patches/patcher -c
|
||||
./_assets/ci/isolate-vendor-check.sh
|
||||
|
||||
dep-ensure: ##@dependencies Dep ensure and apply all patches
|
||||
dep-ensure: ##@dependencies Ensure all dependencies are in place with dep
|
||||
@dep ensure
|
||||
./_assets/patches/patcher
|
||||
|
||||
dep-install: ##@dependencies Install vendoring tool
|
||||
go get -u github.com/golang/dep/cmd/dep
|
||||
|
||||
update-geth: ##@dependencies Update geth (use GETH_BRANCH to optionally set the geth branch name)
|
||||
./_assets/ci/update-geth.sh $(GETH_BRANCH)
|
||||
@echo "**************************************************************"
|
||||
@echo "NOTE: Don't forget to:"
|
||||
@echo "- update the goleveldb dependency revision in Gopkg.toml to match the version used in go-ethereum"
|
||||
@echo "- reconcile any changes to interfaces in transactions/fake (such as PublicTransactionPoolAPI), which are copies from internal geth interfaces"
|
||||
@echo "**************************************************************"
|
||||
|
||||
patch: ##@patching Revert and apply all patches
|
||||
./_assets/patches/patcher
|
||||
|
||||
patch-revert: ##@patching Revert all patches only
|
||||
./_assets/patches/patcher -r
|
||||
|
||||
update-fleet-config: ##@other Update fleets configuration from fleets.status.im
|
||||
./_assets/ci/update-fleet-config.sh
|
||||
@echo "Updating static assets..."
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This is a hack to isolate vendor check in a
|
||||
# separate clean state. Without this, validate-vendor.sh
|
||||
# doesn't like our workflow with patches.
|
||||
#
|
||||
# How it works:
|
||||
# 1) Stashes all changes and checks out to a temporary branch.
|
||||
# 2) Reverts all patches and commits changes.
|
||||
# 3) Runs "dep ensure" and validate-vendor.sh. Saves exit code and message.
|
||||
# 4) Commits any changes.
|
||||
# 5) Goes back to previous branch and removes the temporary branch.
|
||||
# 6) Applies stashed changes.
|
||||
# 7) Prints the message and exits with the exit code.
|
||||
|
||||
timestamp() {
|
||||
date +"%s"
|
||||
}
|
||||
|
||||
tempBranchName="isolated-vendor-check-$(timestamp)"
|
||||
|
||||
# Stash current changes first, apply later before exiting.
|
||||
hasChanges=0
|
||||
changes=($(git status --porcelain))
|
||||
if [ "$changes" ]; then
|
||||
git stash
|
||||
hasChanges=1
|
||||
fi
|
||||
|
||||
branchName="$(git rev-parse --abbrev-ref HEAD)"
|
||||
|
||||
git checkout -b $tempBranchName
|
||||
|
||||
# Revert all patches.
|
||||
$(pwd)/_assets/patches/patcher -r
|
||||
git add .
|
||||
git commit -m "vendor check - auto"
|
||||
|
||||
# Do vendor check.
|
||||
dep ensure
|
||||
msg=$("$(pwd)/_assets/ci/validate-vendor.sh")
|
||||
failed=$?
|
||||
git add .
|
||||
git commit -m "vendor check - auto"
|
||||
|
||||
# Go back to previous branch, clean and apply stashed.
|
||||
git checkout "$branchName"
|
||||
git branch -D $tempBranchName
|
||||
if [ $hasChanges -eq 1 ]; then
|
||||
git stash apply > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
echo $msg
|
||||
exit $failed
|
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script updates the go-ethereum dependency, optionally updating the branch if GETH_BRANCH is provided.
|
||||
# If any changes were made, they will be committed.
|
||||
|
||||
# Exit early if any errors are encountered
|
||||
set -e
|
||||
if [ ! -z "$GETH_BRANCH" ]; then
|
||||
# escape slashes
|
||||
GETH_BRANCH=$(echo $GETH_BRANCH | sed 's@\/@\\\/@g')
|
||||
# Update go-ethereum contraint branch
|
||||
sed -i 'N;N;s@\(\[\[constraint]]\n name = "github.com\/ethereum\/go-ethereum"\n branch =\)\(.*\)@\1 '"\"${GETH_BRANCH}\""'@g' Gopkg.toml
|
||||
fi
|
||||
dep ensure -v -update github.com/ethereum/go-ethereum
|
||||
if ! make dep-ensure; then
|
||||
echo "Please fix patches and rerun. (dep-ensure failed)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
git add Gopkg.lock Gopkg.toml vendor/ _assets/patches/
|
||||
if $(git diff --cached --quiet); then
|
||||
echo "No changes to commit. Geth up to date."
|
||||
exit 0
|
||||
fi
|
||||
git commit --quiet -m "Updating Geth"
|
||||
echo "Geth updated."
|
|
@ -7,5 +7,5 @@ closeComment: >
|
|||
This issue has been automatically closed because there has been no response
|
||||
to our request for more information from the original author. With only the
|
||||
information that is currently in the issue, we don't have enough information
|
||||
to take action. Please reach out if you have or find the answers we need so
|
||||
that we can investigate further.
|
||||
to take action. Please reach out if you have more relevant information or
|
||||
answers to our questions so that we can investigate further.
|
||||
|
|
|
@ -14,11 +14,22 @@ matrix:
|
|||
- go run build/ci.go install
|
||||
- go run build/ci.go test -coverage $TEST_PACKAGES
|
||||
|
||||
# These are the latest Go versions.
|
||||
- os: linux
|
||||
dist: trusty
|
||||
sudo: required
|
||||
go: 1.10.x
|
||||
script:
|
||||
- sudo modprobe fuse
|
||||
- sudo chmod 666 /dev/fuse
|
||||
- sudo chown root:$USER /etc/fuse.conf
|
||||
- go run build/ci.go install
|
||||
- go run build/ci.go test -coverage $TEST_PACKAGES
|
||||
|
||||
# These are the latest Go versions.
|
||||
- os: linux
|
||||
dist: trusty
|
||||
sudo: required
|
||||
go: 1.11.x
|
||||
script:
|
||||
- sudo modprobe fuse
|
||||
- sudo chmod 666 /dev/fuse
|
||||
|
@ -27,7 +38,7 @@ matrix:
|
|||
- go run build/ci.go test -coverage $TEST_PACKAGES
|
||||
|
||||
- os: osx
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
script:
|
||||
- unset -f cd # workaround for https://github.com/travis-ci/travis-ci/issues/8703
|
||||
- go run build/ci.go install
|
||||
|
@ -36,7 +47,7 @@ matrix:
|
|||
# This builder only tests code linters on latest version of Go
|
||||
- os: linux
|
||||
dist: trusty
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- lint
|
||||
git:
|
||||
|
@ -47,7 +58,7 @@ matrix:
|
|||
# This builder does the Ubuntu PPA upload
|
||||
- os: linux
|
||||
dist: trusty
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- ubuntu-ppa
|
||||
git:
|
||||
|
@ -66,7 +77,7 @@ matrix:
|
|||
- os: linux
|
||||
dist: trusty
|
||||
sudo: required
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- azure-linux
|
||||
git:
|
||||
|
@ -100,7 +111,7 @@ matrix:
|
|||
dist: trusty
|
||||
services:
|
||||
- docker
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- azure-linux-mips
|
||||
git:
|
||||
|
@ -144,7 +155,7 @@ matrix:
|
|||
git:
|
||||
submodules: false # avoid cloning ethereum/tests
|
||||
before_install:
|
||||
- curl https://storage.googleapis.com/golang/go1.10.3.linux-amd64.tar.gz | tar -xz
|
||||
- curl https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz | tar -xz
|
||||
- export PATH=`pwd`/go/bin:$PATH
|
||||
- export GOROOT=`pwd`/go
|
||||
- export GOPATH=$HOME/go
|
||||
|
@ -161,7 +172,7 @@ matrix:
|
|||
|
||||
# This builder does the OSX Azure, iOS CocoaPods and iOS Azure uploads
|
||||
- os: osx
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- azure-osx
|
||||
- azure-ios
|
||||
|
@ -190,7 +201,7 @@ matrix:
|
|||
# This builder does the Azure archive purges to avoid accumulating junk
|
||||
- os: linux
|
||||
dist: trusty
|
||||
go: 1.10.x
|
||||
go: 1.11.x
|
||||
env:
|
||||
- azure-purge
|
||||
git:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Build Geth in a stock Go builder container
|
||||
FROM golang:1.10-alpine as builder
|
||||
FROM golang:1.11-alpine as builder
|
||||
|
||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# Build Geth in a stock Go builder container
|
||||
FROM golang:1.10-alpine as builder
|
||||
FROM golang:1.11-alpine as builder
|
||||
|
||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ https://camo.githubusercontent.com/915b7be44ada53c290eb157634330494ebe3e30a/6874
|
|||
)](https://godoc.org/github.com/ethereum/go-ethereum)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/ethereum/go-ethereum)](https://goreportcard.com/report/github.com/ethereum/go-ethereum)
|
||||
[![Travis](https://travis-ci.org/ethereum/go-ethereum.svg?branch=master)](https://travis-ci.org/ethereum/go-ethereum)
|
||||
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ethereum/go-ethereum?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/nthXNEv)
|
||||
|
||||
Automated builds are available for stable releases and the unstable master branch.
|
||||
Binary archives are published at https://geth.ethereum.org/downloads/.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
diff --git a/whisper/whisperv6/api.go b/whisper/whisperv6/api.go
|
||||
index 2de99f293..e0c3284b6 100644
|
||||
index 16b79c7fd..1df3b73dd 100644
|
||||
--- a/whisper/whisperv6/api.go
|
||||
+++ b/whisper/whisperv6/api.go
|
||||
@@ -285,7 +285,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.
|
||||
@@ -284,7 +284,7 @@ func (api *PublicWhisperAPI) Post(ctx context.Context, req NewMessage) (hexutil.
|
||||
}
|
||||
|
||||
|
||||
var result []byte
|
||||
- env, err := whisperMsg.Wrap(params)
|
||||
+ env, err := whisperMsg.Wrap(params, api.w.GetCurrentTime())
|
||||
|
@ -12,34 +12,36 @@ index 2de99f293..e0c3284b6 100644
|
|||
return nil, err
|
||||
}
|
||||
diff --git a/whisper/whisperv6/config.go b/whisper/whisperv6/config.go
|
||||
index 61419de00..3c28263e5 100644
|
||||
index 38eb9551c..213b83698 100644
|
||||
--- a/whisper/whisperv6/config.go
|
||||
+++ b/whisper/whisperv6/config.go
|
||||
@@ -16,14 +16,18 @@
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package whisperv6
|
||||
|
||||
|
||||
+import "time"
|
||||
+
|
||||
// Config represents the configuration state of a whisper node.
|
||||
type Config struct {
|
||||
MaxMessageSize uint32 `toml:",omitempty"`
|
||||
MinimumAcceptedPOW float64 `toml:",omitempty"`
|
||||
+ TimeSource func() time.Time
|
||||
MaxMessageSize uint32 `toml:",omitempty"`
|
||||
MinimumAcceptedPOW float64 `toml:",omitempty"`
|
||||
RestrictConnectionBetweenLightClients bool `toml:",omitempty"`
|
||||
+ TimeSource func() time.Time
|
||||
}
|
||||
|
||||
|
||||
// DefaultConfig represents (shocker!) the default configuration.
|
||||
var DefaultConfig = Config{
|
||||
MaxMessageSize: DefaultMaxMessageSize,
|
||||
MinimumAcceptedPOW: DefaultMinimumPoW,
|
||||
+ TimeSource: time.Now,
|
||||
@@ -28,4 +31,5 @@ var DefaultConfig = Config{
|
||||
MaxMessageSize: DefaultMaxMessageSize,
|
||||
MinimumAcceptedPOW: DefaultMinimumPoW,
|
||||
RestrictConnectionBetweenLightClients: true,
|
||||
+ TimeSource: time.Now,
|
||||
}
|
||||
diff --git a/whisper/whisperv6/envelope.go b/whisper/whisperv6/envelope.go
|
||||
index c42d1fa8a..3b65fdba0 100644
|
||||
--- a/whisper/whisperv6/envelope.go
|
||||
+++ b/whisper/whisperv6/envelope.go
|
||||
@@ -62,9 +62,9 @@ func (e *Envelope) rlpWithoutNonce() []byte {
|
||||
|
||||
|
||||
// NewEnvelope wraps a Whisper message with expiration and destination data
|
||||
// included into an envelope for network forwarding.
|
||||
-func NewEnvelope(ttl uint32, topic TopicType, msg *sentMessage) *Envelope {
|
||||
|
@ -59,12 +61,12 @@ index 2d4e86244..a12b445e2 100644
|
|||
mrand "math/rand"
|
||||
"strconv"
|
||||
+ "time"
|
||||
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
@@ -234,7 +235,7 @@ func generateSecureRandomData(length int) ([]byte, error) {
|
||||
}
|
||||
|
||||
|
||||
// Wrap bundles the message into an Envelope to transmit over the network.
|
||||
-func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err error) {
|
||||
+func (msg *sentMessage) Wrap(options *MessageParams, now time.Time) (envelope *Envelope, err error) {
|
||||
|
@ -74,35 +76,37 @@ index 2d4e86244..a12b445e2 100644
|
|||
@@ -254,7 +255,7 @@ func (msg *sentMessage) Wrap(options *MessageParams) (envelope *Envelope, err er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
- envelope = NewEnvelope(options.TTL, options.Topic, msg)
|
||||
+ envelope = NewEnvelope(options.TTL, options.Topic, msg, now)
|
||||
if err = envelope.Seal(options); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go
|
||||
index 8d56ece64..697f0ecb8 100644
|
||||
index 014e93c12..a57ff6428 100644
|
||||
--- a/whisper/whisperv6/whisper.go
|
||||
+++ b/whisper/whisperv6/whisper.go
|
||||
@@ -93,4 +92,6 @@ type Whisper struct {
|
||||
@@ -91,6 +91,8 @@ type Whisper struct {
|
||||
mailServer MailServer // MailServer interface
|
||||
|
||||
envelopeFeed event.Feed
|
||||
+
|
||||
+ timeSource func() time.Time // source of time for whisper
|
||||
}
|
||||
|
||||
|
||||
// New creates a Whisper client ready to communicate through the Ethereum P2P network.
|
||||
@@ -110,6 +112,7 @@ func New(cfg *Config) *Whisper {
|
||||
@@ -109,6 +111,7 @@ func New(cfg *Config) *Whisper {
|
||||
p2pMsgQueue: make(chan *Envelope, messageQueueLimit),
|
||||
quit: make(chan struct{}),
|
||||
syncAllowance: DefaultSyncAllowance,
|
||||
+ timeSource: cfg.TimeSource,
|
||||
}
|
||||
|
||||
|
||||
whisper.filters = NewFilters(whisper)
|
||||
@@ -215,6 +218,11 @@ func (whisper *Whisper) APIs() []rpc.API {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+// GetCurrentTime returns current time.
|
||||
+func (whisper *Whisper) GetCurrentTime() time.Time {
|
||||
+ return whisper.timeSource()
|
||||
|
@ -111,16 +115,16 @@ index 8d56ece64..697f0ecb8 100644
|
|||
// RegisterServer registers MailServer interface.
|
||||
// MailServer will process all the incoming messages with p2pRequestCode.
|
||||
func (whisper *Whisper) RegisterServer(server MailServer) {
|
||||
@@ -829,7 +837,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
|
||||
@@ -846,7 +854,7 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
|
||||
// appropriate time-stamp. In case of error, connection should be dropped.
|
||||
// param isP2P indicates whether the message is peer-to-peer (should not be forwarded).
|
||||
func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
||||
- now := uint32(time.Now().Unix())
|
||||
+ now := uint32(whisper.timeSource().Unix())
|
||||
sent := envelope.Expiry - envelope.TTL
|
||||
|
||||
|
||||
if sent > now {
|
||||
@@ -988,7 +996,7 @@ func (whisper *Whisper) expire() {
|
||||
@@ -989,7 +997,7 @@ func (whisper *Whisper) expire() {
|
||||
whisper.statsMu.Lock()
|
||||
defer whisper.statsMu.Unlock()
|
||||
whisper.stats.reset()
|
|
@ -1,5 +1,5 @@
|
|||
diff --git a/whisper/whisperv6/events.go b/whisper/whisperv6/events.go
|
||||
index 1665539..fe7570e 100644
|
||||
index 1665539d6..fe7570ed5 100644
|
||||
--- a/whisper/whisperv6/events.go
|
||||
+++ b/whisper/whisperv6/events.go
|
||||
@@ -13,10 +13,14 @@ const (
|
||||
|
@ -24,7 +24,7 @@ index 1665539..fe7570e 100644
|
|||
+ Data interface{}
|
||||
}
|
||||
diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go
|
||||
index 91d4482..6a937a2 100644
|
||||
index ccc733165..dbe4c3fc0 100644
|
||||
--- a/whisper/whisperv6/whisper.go
|
||||
+++ b/whisper/whisperv6/whisper.go
|
||||
@@ -49,6 +49,12 @@ type Statistics struct {
|
||||
|
@ -38,9 +38,9 @@ index 91d4482..6a937a2 100644
|
|||
+}
|
||||
+
|
||||
const (
|
||||
maxMsgSizeIdx = iota // Maximal message length allowed by the whisper node
|
||||
overflowIdx // Indicator of message queue overflow
|
||||
@@ -378,8 +384,8 @@ func (whisper *Whisper) RequestHistoricMessages(peerID []byte, envelope *Envelop
|
||||
maxMsgSizeIdx = iota // Maximal message length allowed by the whisper node
|
||||
overflowIdx // Indicator of message queue overflow
|
||||
@@ -397,8 +403,8 @@ func (whisper *Whisper) RequestHistoricMessages(peerID []byte, envelope *Envelop
|
||||
return p2p.Send(p.ws, p2pRequestCode, envelope)
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ index 91d4482..6a937a2 100644
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -835,15 +841,49 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
|
||||
@@ -852,15 +858,49 @@ func (whisper *Whisper) runMessageLoop(p *Peer, rw p2p.MsgReadWriter) error {
|
||||
}
|
||||
case p2pRequestCompleteCode:
|
||||
if p.trusted {
|
||||
|
@ -103,7 +103,7 @@ index 91d4482..6a937a2 100644
|
|||
})
|
||||
}
|
||||
default:
|
||||
@@ -927,6 +967,10 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
||||
@@ -944,6 +984,10 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
|
||||
whisper.postEvent(envelope, isP2P) // notify the local node about the new message
|
||||
if whisper.mailServer != nil {
|
||||
whisper.mailServer.Archive(envelope)
|
||||
|
@ -114,7 +114,7 @@ index 91d4482..6a937a2 100644
|
|||
}
|
||||
}
|
||||
return true, nil
|
||||
@@ -985,9 +1029,17 @@ func (whisper *Whisper) processQueue() {
|
||||
@@ -986,9 +1030,17 @@ func (whisper *Whisper) processQueue() {
|
||||
|
||||
case e = <-whisper.messageQueue:
|
||||
whisper.filters.NotifyWatchers(e, false)
|
|
@ -1,7 +1,7 @@
|
|||
# Status Patches for geth (go-ethereum)
|
||||
---
|
||||
Status Patches for geth (go-ethereum)
|
||||
=====================================
|
||||
|
||||
Status-go uses [go-ethereum](https://github.com/ethereum/go-ethereum) (**upstream**) as its dependency. As any other Go dependency `go-ethereum` code is vendored and stored in `vendor/` folder.
|
||||
status-go uses [go-ethereum](https://github.com/status-im/go-ethereum) as its dependency. As any other Go dependency `go-ethereum` code is vendored and stored in `vendor/` folder.
|
||||
|
||||
However, there are a few changes has been made to the upstream, that are specific to Status and should not be merged to the upstream. We keep those changes as a set of patches, that can be applied upon each next release of `go-ethereum`. Patched version of `go-ethereum` is available in vendor folder.
|
||||
|
189
vendor/github.com/ethereum/go-ethereum/_assets/patches/patcher
generated
vendored
Executable file
189
vendor/github.com/ethereum/go-ethereum/_assets/patches/patcher
generated
vendored
Executable file
|
@ -0,0 +1,189 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Default behaviour:
|
||||
# Reverts all patches in patch dir, notes down the ones
|
||||
# which were previously applied. Applies all from the beginning
|
||||
# and reports about previously unapplied patches. If there's
|
||||
# an error, reverts the last one and stops.
|
||||
#
|
||||
# Usage: ./patcher -b <base_path> -r -v
|
||||
# -b: <base_path> is the target location relative to which patches will be applied
|
||||
# -p: <patch_path> is where to take the patches from (default is geth)
|
||||
# -r: reverts all and exit if this flag is present
|
||||
# -c: reverts all to see what's applied, applies all previously applied back again,
|
||||
# reports unapplied patches in this branch by comparing with "develop" including
|
||||
# uncommitted ones and exits (with 1 if there are any)
|
||||
# -v: verbose error reporting about failed patch
|
||||
#
|
||||
# If -b is not present, default path is as below ($basepath).
|
||||
|
||||
dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
# Patches path is geth unless specified.
|
||||
patches=("$dir"/*.patch)
|
||||
|
||||
# Use this branch as a reference for comparing patches
|
||||
# in current branch (-c option).
|
||||
baseBranch="develop"
|
||||
|
||||
# Base path is the current root project unless specified.
|
||||
basepath="."
|
||||
|
||||
gitApply() {
|
||||
f=$1
|
||||
basepath=$2
|
||||
verbose=$3
|
||||
|
||||
if [ $verbose -eq 1 ]; then
|
||||
if [ $basepath == "." ]; then
|
||||
git apply "$f"
|
||||
else
|
||||
git apply "$f" --directory="$basepath"
|
||||
fi
|
||||
else
|
||||
if [ $basepath == "." ]; then
|
||||
git apply "$f" > /dev/null 2>&1
|
||||
else
|
||||
git apply "$f" --directory="$basepath" > /dev/null 2>&1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
gitApplyReverse() {
|
||||
f=$1
|
||||
basepath=$2
|
||||
|
||||
if [ $basepath == "." ]; then
|
||||
git apply "$f" -R > /dev/null 2>&1
|
||||
else
|
||||
git apply "$f" --directory="$basepath" -R > /dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
verbose=0
|
||||
revert=0
|
||||
compare=0
|
||||
while getopts b:p:rcv opt; do
|
||||
case $opt in
|
||||
b)
|
||||
basepath=$OPTARG
|
||||
;;
|
||||
p)
|
||||
patches=("$dir"/$OPTARG/*.patch)
|
||||
;;
|
||||
r)
|
||||
revert=1
|
||||
;;
|
||||
c)
|
||||
compare=1
|
||||
;;
|
||||
v)
|
||||
verbose=1
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid flag: -$OPTARG" >&2
|
||||
exit
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $revert -eq 1 ]; then
|
||||
# Reverts in reverse order and exits.
|
||||
for ((i=${#patches[@]}-1; i>=0; i--)); do
|
||||
gitApplyReverse "${patches[$i]}" "$basepath" 0
|
||||
done
|
||||
echo "Reverted all."
|
||||
exit
|
||||
fi
|
||||
if [ $compare -eq 1 ]; then
|
||||
applied=()
|
||||
unapplied=()
|
||||
# Finds applied patches using reverse order and
|
||||
# notes them down.
|
||||
for ((i=${#patches[@]}-1; i>=0; i--)); do
|
||||
f=${patches[$i]}
|
||||
gitApplyReverse "$f" "$basepath"
|
||||
if [ $? -ne 0 ]; then
|
||||
unapplied+=("$f")
|
||||
else
|
||||
applied+=("$f")
|
||||
fi
|
||||
done
|
||||
# Applies reverted patches back again.
|
||||
for ((i=${#applied[@]}-1; i>=0; i--)); do
|
||||
f=${applied[$i]}
|
||||
gitApply "$f" "$basepath" 0
|
||||
done
|
||||
# Sorts out new patches' paths by comparing with base branch.
|
||||
fromBaseBranch=($(git diff $baseBranch --stat | grep "\\.patch" |
|
||||
while IFS=" " read -r -a line; do
|
||||
path="$(pwd)/${line[0]}"
|
||||
echo "$path"
|
||||
done
|
||||
))
|
||||
# Also does the same with uncommitted.
|
||||
uncommitted=($(git status -u --porcelain | grep "\\.patch" |
|
||||
while IFS=" " read -r -a line; do
|
||||
length=${#line[@]}
|
||||
path="$(pwd)/${line[$((length - 1))]}"
|
||||
echo "$path"
|
||||
done
|
||||
))
|
||||
newPatches=( "${fromBaseBranch[@]}" "${uncommitted[@]}" )
|
||||
# Checks new patches and exits with 1 if there are unapplied.
|
||||
hasUnapplied=0
|
||||
for newPatch in "${newPatches[@]}"; do
|
||||
for unapp in "${unapplied[@]}"; do
|
||||
if [ "$unapp" == "$newPatch" ]; then
|
||||
echo "Recently added/changed but not applied: $unapp"
|
||||
hasUnapplied=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
exit $hasUnapplied
|
||||
fi
|
||||
|
||||
applied=()
|
||||
|
||||
echo -en "\\n"
|
||||
echo "Previously applied:"
|
||||
echo "==================="
|
||||
# Reverts every patch in reverse order to see
|
||||
# which was previously applied.
|
||||
for ((i=${#patches[@]}-1; i>=0; i--)); do
|
||||
f=${patches[$i]}
|
||||
gitApplyReverse "$f" "$basepath"
|
||||
if [ $? -eq 0 ]; then
|
||||
applied+=("$f")
|
||||
echo "$f"
|
||||
fi
|
||||
done
|
||||
echo "==================="
|
||||
echo -en "\\n"
|
||||
|
||||
# Applies every patch from the beginning.
|
||||
for ((i=0; i<${#patches[@]}; i++)); do
|
||||
f=${patches[$i]}
|
||||
# If not applied, report it new.
|
||||
has=0
|
||||
for patch in "${applied[@]}"; do
|
||||
if [ "$patch" == "$f" ]; then
|
||||
has=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $has -eq 0 ]; then
|
||||
echo "Applying new: $f"
|
||||
echo -en "\\n"
|
||||
fi
|
||||
gitApply "$f" "$basepath" $verbose
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed and reverting: $f"
|
||||
gitApplyReverse "$f" "$basepath"
|
||||
echo -en "\\n"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
echo -en "\\n"
|
||||
echo "Done."
|
|
@ -69,7 +69,7 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
|
|||
database := ethdb.NewMemDatabase()
|
||||
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
|
||||
genesis.MustCommit(database)
|
||||
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{})
|
||||
blockchain, _ := core.NewBlockChain(database, nil, genesis.Config, ethash.NewFaker(), vm.Config{}, nil)
|
||||
|
||||
backend := &SimulatedBackend{
|
||||
database: database,
|
||||
|
|
|
@ -103,7 +103,12 @@ func NewType(t string) (typ Type, err error) {
|
|||
return typ, err
|
||||
}
|
||||
// parse the type and size of the abi-type.
|
||||
parsedType := typeRegex.FindAllStringSubmatch(t, -1)[0]
|
||||
matches := typeRegex.FindAllStringSubmatch(t, -1)
|
||||
if len(matches) == 0 {
|
||||
return Type{}, fmt.Errorf("invalid type '%v'", t)
|
||||
}
|
||||
parsedType := matches[0]
|
||||
|
||||
// varSize is the size of the variable
|
||||
var varSize int
|
||||
if len(parsedType[3]) > 0 {
|
||||
|
|
|
@ -25,8 +25,17 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
var (
|
||||
maxUint256 = big.NewInt(0).Add(
|
||||
big.NewInt(0).Exp(big.NewInt(2), big.NewInt(256), nil),
|
||||
big.NewInt(-1))
|
||||
maxInt256 = big.NewInt(0).Add(
|
||||
big.NewInt(0).Exp(big.NewInt(2), big.NewInt(255), nil),
|
||||
big.NewInt(-1))
|
||||
)
|
||||
|
||||
// reads the integer based on its kind
|
||||
func readInteger(kind reflect.Kind, b []byte) interface{} {
|
||||
func readInteger(typ byte, kind reflect.Kind, b []byte) interface{} {
|
||||
switch kind {
|
||||
case reflect.Uint8:
|
||||
return b[len(b)-1]
|
||||
|
@ -45,7 +54,20 @@ func readInteger(kind reflect.Kind, b []byte) interface{} {
|
|||
case reflect.Int64:
|
||||
return int64(binary.BigEndian.Uint64(b[len(b)-8:]))
|
||||
default:
|
||||
return new(big.Int).SetBytes(b)
|
||||
// the only case lefts for integer is int256/uint256.
|
||||
// big.SetBytes can't tell if a number is negative, positive on itself.
|
||||
// On EVM, if the returned number > max int256, it is negative.
|
||||
ret := new(big.Int).SetBytes(b)
|
||||
if typ == UintTy {
|
||||
return ret
|
||||
}
|
||||
|
||||
if ret.Cmp(maxInt256) > 0 {
|
||||
ret.Add(maxUint256, big.NewInt(0).Neg(ret))
|
||||
ret.Add(ret, big.NewInt(1))
|
||||
ret.Neg(ret)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +201,7 @@ func toGoType(index int, t Type, output []byte) (interface{}, error) {
|
|||
case StringTy: // variable arrays are written at the end of the return bytes
|
||||
return string(output[begin : begin+end]), nil
|
||||
case IntTy, UintTy:
|
||||
return readInteger(t.Kind, returnOutput), nil
|
||||
return readInteger(t.T, t.Kind, returnOutput), nil
|
||||
case BoolTy:
|
||||
return readBool(returnOutput)
|
||||
case AddressTy:
|
||||
|
|
|
@ -220,26 +220,34 @@ func storeNewKey(ks keyStore, rand io.Reader, auth string) (*Key, accounts.Accou
|
|||
return key, a, err
|
||||
}
|
||||
|
||||
func writeKeyFile(file string, content []byte) error {
|
||||
func writeTemporaryKeyFile(file string, content []byte) (string, error) {
|
||||
// Create the keystore directory with appropriate permissions
|
||||
// in case it is not present yet.
|
||||
const dirPerm = 0700
|
||||
if err := os.MkdirAll(filepath.Dir(file), dirPerm); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
// Atomic write: create a temporary hidden file first
|
||||
// then move it into place. TempFile assigns mode 0600.
|
||||
f, err := ioutil.TempFile(filepath.Dir(file), "."+filepath.Base(file)+".tmp")
|
||||
if err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
if _, err := f.Write(content); err != nil {
|
||||
f.Close()
|
||||
os.Remove(f.Name())
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
f.Close()
|
||||
return os.Rename(f.Name(), file)
|
||||
return f.Name(), nil
|
||||
}
|
||||
|
||||
func writeKeyFile(file string, content []byte) error {
|
||||
name, err := writeTemporaryKeyFile(file, content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(name, file)
|
||||
}
|
||||
|
||||
// keyFileName implements the naming convention for keyfiles:
|
||||
|
|
|
@ -79,7 +79,7 @@ type unlocked struct {
|
|||
// NewKeyStore creates a keystore for the given directory.
|
||||
func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore {
|
||||
keydir, _ = filepath.Abs(keydir)
|
||||
ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP}}
|
||||
ks := &KeyStore{storage: &keyStorePassphrase{keydir, scryptN, scryptP, false}}
|
||||
ks.init(keydir)
|
||||
return ks
|
||||
}
|
||||
|
|
27
vendor/github.com/ethereum/go-ethereum/accounts/keystore/keystore_passphrase.go
generated
vendored
27
vendor/github.com/ethereum/go-ethereum/accounts/keystore/keystore_passphrase.go
generated
vendored
|
@ -35,6 +35,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
@ -73,6 +74,10 @@ type keyStorePassphrase struct {
|
|||
keysDirPath string
|
||||
scryptN int
|
||||
scryptP int
|
||||
// skipKeyFileVerification disables the security-feature which does
|
||||
// reads and decrypts any newly created keyfiles. This should be 'false' in all
|
||||
// cases except tests -- setting this to 'true' is not recommended.
|
||||
skipKeyFileVerification bool
|
||||
}
|
||||
|
||||
func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string) (*Key, error) {
|
||||
|
@ -94,7 +99,7 @@ func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string)
|
|||
|
||||
// StoreKey generates a key, encrypts with 'auth' and stores in the given directory
|
||||
func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) {
|
||||
_, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP}, rand.Reader, auth)
|
||||
_, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP, false}, rand.Reader, auth)
|
||||
return a.Address, err
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,25 @@ func (ks keyStorePassphrase) StoreKey(filename string, key *Key, auth string) er
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeKeyFile(filename, keyjson)
|
||||
// Write into temporary file
|
||||
tmpName, err := writeTemporaryKeyFile(filename, keyjson)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ks.skipKeyFileVerification {
|
||||
// Verify that we can decrypt the file with the given password.
|
||||
_, err = ks.GetKey(key.Address, tmpName, auth)
|
||||
if err != nil {
|
||||
msg := "An error was encountered when saving and verifying the keystore file. \n" +
|
||||
"This indicates that the keystore is corrupted. \n" +
|
||||
"The corrupted file is stored at \n%v\n" +
|
||||
"Please file a ticket at:\n\n" +
|
||||
"https://github.com/ethereum/go-ethereum/issues." +
|
||||
"The error was : %s"
|
||||
return fmt.Errorf(msg, tmpName, err)
|
||||
}
|
||||
}
|
||||
return os.Rename(tmpName, filename)
|
||||
}
|
||||
|
||||
func (ks keyStorePassphrase) JoinPath(filename string) string {
|
||||
|
|
|
@ -23,8 +23,8 @@ environment:
|
|||
install:
|
||||
- git submodule update --init
|
||||
- rmdir C:\go /s /q
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.10.3.windows-%GETH_ARCH%.zip
|
||||
- 7z x go1.10.3.windows-%GETH_ARCH%.zip -y -oC:\ > NUL
|
||||
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.11.windows-%GETH_ARCH%.zip
|
||||
- 7z x go1.11.windows-%GETH_ARCH%.zip -y -oC:\ > NUL
|
||||
- go version
|
||||
- gcc --version
|
||||
|
||||
|
|
|
@ -225,7 +225,7 @@ func initializeSecrets(c *cli.Context) error {
|
|||
if _, err := os.Stat(location); err == nil {
|
||||
return fmt.Errorf("file %v already exists, will not overwrite", location)
|
||||
}
|
||||
err = ioutil.WriteFile(location, masterSeed, 0700)
|
||||
err = ioutil.WriteFile(location, masterSeed, 0400)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -540,14 +540,14 @@ func readMasterKey(ctx *cli.Context) ([]byte, error) {
|
|||
|
||||
// checkFile is a convenience function to check if a file
|
||||
// * exists
|
||||
// * is mode 0600
|
||||
// * is mode 0400
|
||||
func checkFile(filename string) error {
|
||||
info, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed stat on %s: %v", filename, err)
|
||||
}
|
||||
// Check the unix permission bits
|
||||
if info.Mode().Perm()&077 != 0 {
|
||||
if info.Mode().Perm()&0377 != 0 {
|
||||
return fmt.Errorf("file (%v) has insecure file permissions (%v)", filename, info.Mode().String())
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -21,21 +21,33 @@ Private key information can be printed by using the `--private` flag;
|
|||
make sure to use this feature with great caution!
|
||||
|
||||
|
||||
### `ethkey sign <keyfile> <message/file>`
|
||||
### `ethkey signmessage <keyfile> <message/file>`
|
||||
|
||||
Sign the message with a keyfile.
|
||||
It is possible to refer to a file containing the message.
|
||||
To sign a message contained in a file, use the `--msgfile` flag.
|
||||
|
||||
|
||||
### `ethkey verify <address> <signature> <message/file>`
|
||||
### `ethkey verifymessage <address> <signature> <message/file>`
|
||||
|
||||
Verify the signature of the message.
|
||||
It is possible to refer to a file containing the message.
|
||||
To sign a message contained in a file, use the --msgfile flag.
|
||||
|
||||
|
||||
### `ethkey changepassphrase <keyfile>`
|
||||
|
||||
Change the passphrase of a keyfile.
|
||||
use the `--newpasswordfile` to point to the new password file.
|
||||
|
||||
|
||||
## Passphrases
|
||||
|
||||
For every command that uses a keyfile, you will be prompted to provide the
|
||||
passphrase for decrypting the keyfile. To avoid this message, it is possible
|
||||
to pass the passphrase by using the `--passphrase` flag pointing to a file that
|
||||
to pass the passphrase by using the `--passwordfile` flag pointing to a file that
|
||||
contains the passphrase.
|
||||
|
||||
## JSON
|
||||
|
||||
In case you need to output the result in a JSON format, you shall by using the `--json` flag.
|
||||
|
|
|
@ -44,7 +44,7 @@ func disasmCmd(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
code := strings.TrimSpace(string(in[:]))
|
||||
code := strings.TrimSpace(string(in))
|
||||
fmt.Printf("%v\n", code)
|
||||
return asm.PrintDisassembled(code)
|
||||
}
|
||||
|
|
|
@ -80,13 +80,13 @@ func runCmd(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
var (
|
||||
tracer vm.Tracer
|
||||
debugLogger *vm.StructLogger
|
||||
statedb *state.StateDB
|
||||
chainConfig *params.ChainConfig
|
||||
sender = common.BytesToAddress([]byte("sender"))
|
||||
receiver = common.BytesToAddress([]byte("receiver"))
|
||||
blockNumber uint64
|
||||
tracer vm.Tracer
|
||||
debugLogger *vm.StructLogger
|
||||
statedb *state.StateDB
|
||||
chainConfig *params.ChainConfig
|
||||
sender = common.BytesToAddress([]byte("sender"))
|
||||
receiver = common.BytesToAddress([]byte("receiver"))
|
||||
genesisConfig *core.Genesis
|
||||
)
|
||||
if ctx.GlobalBool(MachineFlag.Name) {
|
||||
tracer = NewJSONLogger(logconfig, os.Stdout)
|
||||
|
@ -98,13 +98,14 @@ func runCmd(ctx *cli.Context) error {
|
|||
}
|
||||
if ctx.GlobalString(GenesisFlag.Name) != "" {
|
||||
gen := readGenesis(ctx.GlobalString(GenesisFlag.Name))
|
||||
genesisConfig = gen
|
||||
db := ethdb.NewMemDatabase()
|
||||
genesis := gen.ToBlock(db)
|
||||
statedb, _ = state.New(genesis.Root(), state.NewDatabase(db))
|
||||
chainConfig = gen.Config
|
||||
blockNumber = gen.Number
|
||||
} else {
|
||||
statedb, _ = state.New(common.Hash{}, state.NewDatabase(ethdb.NewMemDatabase()))
|
||||
genesisConfig = new(core.Genesis)
|
||||
}
|
||||
if ctx.GlobalString(SenderFlag.Name) != "" {
|
||||
sender = common.HexToAddress(ctx.GlobalString(SenderFlag.Name))
|
||||
|
@ -156,13 +157,19 @@ func runCmd(ctx *cli.Context) error {
|
|||
}
|
||||
|
||||
initialGas := ctx.GlobalUint64(GasFlag.Name)
|
||||
if genesisConfig.GasLimit != 0 {
|
||||
initialGas = genesisConfig.GasLimit
|
||||
}
|
||||
runtimeConfig := runtime.Config{
|
||||
Origin: sender,
|
||||
State: statedb,
|
||||
GasLimit: initialGas,
|
||||
GasPrice: utils.GlobalBig(ctx, PriceFlag.Name),
|
||||
Value: utils.GlobalBig(ctx, ValueFlag.Name),
|
||||
BlockNumber: new(big.Int).SetUint64(blockNumber),
|
||||
Difficulty: genesisConfig.Difficulty,
|
||||
Time: new(big.Int).SetUint64(genesisConfig.Timestamp),
|
||||
Coinbase: genesisConfig.Coinbase,
|
||||
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
|
||||
EVMConfig: vm.Config{
|
||||
Tracer: tracer,
|
||||
Debug: ctx.GlobalBool(DebugFlag.Name) || ctx.GlobalBool(MachineFlag.Name),
|
||||
|
|
|
@ -157,7 +157,8 @@ func main() {
|
|||
if blob, err = ioutil.ReadFile(*accPassFlag); err != nil {
|
||||
log.Crit("Failed to read account password contents", "file", *accPassFlag, "err", err)
|
||||
}
|
||||
pass := string(blob)
|
||||
// Delete trailing newline in password
|
||||
pass := strings.TrimSuffix(string(blob), "\n")
|
||||
|
||||
ks := keystore.NewKeyStore(filepath.Join(os.Getenv("HOME"), ".faucet", "keys"), keystore.StandardScryptN, keystore.StandardScryptP)
|
||||
if blob, err = ioutil.ReadFile(*accJSONFlag); err != nil {
|
||||
|
@ -198,6 +199,8 @@ type faucet struct {
|
|||
|
||||
keystore *keystore.KeyStore // Keystore containing the single signer
|
||||
account accounts.Account // Account funding user faucet requests
|
||||
head *types.Header // Current head header of the faucet
|
||||
balance *big.Int // Current balance of the faucet
|
||||
nonce uint64 // Current pending nonce of the faucet
|
||||
price *big.Int // Current gas price to issue funds with
|
||||
|
||||
|
@ -323,33 +326,30 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
|
|||
nonce uint64
|
||||
err error
|
||||
)
|
||||
for {
|
||||
// Attempt to retrieve the stats, may error on no faucet connectivity
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
head, err = f.client.HeaderByNumber(ctx, nil)
|
||||
if err == nil {
|
||||
balance, err = f.client.BalanceAt(ctx, f.account.Address, head.Number)
|
||||
if err == nil {
|
||||
nonce, err = f.client.NonceAt(ctx, f.account.Address, nil)
|
||||
}
|
||||
for head == nil || balance == nil {
|
||||
// Retrieve the current stats cached by the faucet
|
||||
f.lock.RLock()
|
||||
if f.head != nil {
|
||||
head = types.CopyHeader(f.head)
|
||||
}
|
||||
cancel()
|
||||
if f.balance != nil {
|
||||
balance = new(big.Int).Set(f.balance)
|
||||
}
|
||||
nonce = f.nonce
|
||||
f.lock.RUnlock()
|
||||
|
||||
// If stats retrieval failed, wait a bit and retry
|
||||
if err != nil {
|
||||
if err = sendError(conn, errors.New("Faucet offline: "+err.Error())); err != nil {
|
||||
if head == nil || balance == nil {
|
||||
// Report the faucet offline until initial stats are ready
|
||||
if err = sendError(conn, errors.New("Faucet offline")); err != nil {
|
||||
log.Warn("Failed to send faucet error to client", "err", err)
|
||||
return
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
continue
|
||||
}
|
||||
// Initial stats reported successfully, proceed with user interaction
|
||||
break
|
||||
}
|
||||
// Send over the initial stats and the latest header
|
||||
if err = send(conn, map[string]interface{}{
|
||||
"funds": balance.Div(balance, ether),
|
||||
"funds": new(big.Int).Div(balance, ether),
|
||||
"funded": nonce,
|
||||
"peers": f.stack.Server().PeerCount(),
|
||||
"requests": f.reqs,
|
||||
|
@ -519,6 +519,47 @@ func (f *faucet) apiHandler(conn *websocket.Conn) {
|
|||
}
|
||||
}
|
||||
|
||||
// refresh attempts to retrieve the latest header from the chain and extract the
|
||||
// associated faucet balance and nonce for connectivity caching.
|
||||
func (f *faucet) refresh(head *types.Header) error {
|
||||
// Ensure a state update does not run for too long
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// If no header was specified, use the current chain head
|
||||
var err error
|
||||
if head == nil {
|
||||
if head, err = f.client.HeaderByNumber(ctx, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Retrieve the balance, nonce and gas price from the current head
|
||||
var (
|
||||
balance *big.Int
|
||||
nonce uint64
|
||||
price *big.Int
|
||||
)
|
||||
if balance, err = f.client.BalanceAt(ctx, f.account.Address, head.Number); err != nil {
|
||||
return err
|
||||
}
|
||||
if nonce, err = f.client.NonceAt(ctx, f.account.Address, head.Number); err != nil {
|
||||
return err
|
||||
}
|
||||
if price, err = f.client.SuggestGasPrice(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
// Everything succeeded, update the cached stats and eject old requests
|
||||
f.lock.Lock()
|
||||
f.head, f.balance = head, balance
|
||||
f.price, f.nonce = price, nonce
|
||||
for len(f.reqs) > 0 && f.reqs[0].Tx.Nonce() < f.nonce {
|
||||
f.reqs = f.reqs[1:]
|
||||
}
|
||||
f.lock.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// loop keeps waiting for interesting events and pushes them out to connected
|
||||
// websockets.
|
||||
func (f *faucet) loop() {
|
||||
|
@ -536,45 +577,27 @@ func (f *faucet) loop() {
|
|||
go func() {
|
||||
for head := range update {
|
||||
// New chain head arrived, query the current stats and stream to clients
|
||||
var (
|
||||
balance *big.Int
|
||||
nonce uint64
|
||||
price *big.Int
|
||||
err error
|
||||
)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
balance, err = f.client.BalanceAt(ctx, f.account.Address, head.Number)
|
||||
if err == nil {
|
||||
nonce, err = f.client.NonceAt(ctx, f.account.Address, nil)
|
||||
if err == nil {
|
||||
price, err = f.client.SuggestGasPrice(ctx)
|
||||
}
|
||||
timestamp := time.Unix(head.Time.Int64(), 0)
|
||||
if time.Since(timestamp) > time.Hour {
|
||||
log.Warn("Skipping faucet refresh, head too old", "number", head.Number, "hash", head.Hash(), "age", common.PrettyAge(timestamp))
|
||||
continue
|
||||
}
|
||||
cancel()
|
||||
|
||||
// If querying the data failed, try for the next block
|
||||
if err != nil {
|
||||
if err := f.refresh(head); err != nil {
|
||||
log.Warn("Failed to update faucet state", "block", head.Number, "hash", head.Hash(), "err", err)
|
||||
continue
|
||||
} else {
|
||||
log.Info("Updated faucet state", "block", head.Number, "hash", head.Hash(), "balance", balance, "nonce", nonce, "price", price)
|
||||
}
|
||||
// Faucet state retrieved, update locally and send to clients
|
||||
balance = new(big.Int).Div(balance, ether)
|
||||
|
||||
f.lock.Lock()
|
||||
f.price, f.nonce = price, nonce
|
||||
for len(f.reqs) > 0 && f.reqs[0].Tx.Nonce() < f.nonce {
|
||||
f.reqs = f.reqs[1:]
|
||||
}
|
||||
f.lock.Unlock()
|
||||
|
||||
f.lock.RLock()
|
||||
log.Info("Updated faucet state", "number", head.Number, "hash", head.Hash(), "age", common.PrettyAge(timestamp), "balance", f.balance, "nonce", f.nonce, "price", f.price)
|
||||
|
||||
balance := new(big.Int).Div(f.balance, ether)
|
||||
peers := f.stack.Server().PeerCount()
|
||||
|
||||
for _, conn := range f.conns {
|
||||
if err := send(conn, map[string]interface{}{
|
||||
"funds": balance,
|
||||
"funded": f.nonce,
|
||||
"peers": f.stack.Server().PeerCount(),
|
||||
"peers": peers,
|
||||
"requests": f.reqs,
|
||||
}, time.Second); err != nil {
|
||||
log.Warn("Failed to send stats to client", "err", err)
|
||||
|
|
|
@ -340,9 +340,9 @@ func importPreimages(ctx *cli.Context) error {
|
|||
|
||||
start := time.Now()
|
||||
if err := utils.ImportPreimages(diskdb, ctx.Args().First()); err != nil {
|
||||
utils.Fatalf("Export error: %v\n", err)
|
||||
utils.Fatalf("Import error: %v\n", err)
|
||||
}
|
||||
fmt.Printf("Export done in %v\n", time.Since(start))
|
||||
fmt.Printf("Import done in %v\n", time.Since(start))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -168,6 +168,9 @@ func makeFullNode(ctx *cli.Context) *node.Node {
|
|||
if ctx.GlobalIsSet(utils.WhisperMinPOWFlag.Name) {
|
||||
cfg.Shh.MinimumAcceptedPOW = ctx.Float64(utils.WhisperMinPOWFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(utils.WhisperRestrictConnectionBetweenLightClientsFlag.Name) {
|
||||
cfg.Shh.RestrictConnectionBetweenLightClients = true
|
||||
}
|
||||
utils.RegisterShhService(stack, &cfg.Shh)
|
||||
}
|
||||
|
||||
|
|
|
@ -130,6 +130,8 @@ var (
|
|||
utils.NoCompactionFlag,
|
||||
utils.GpoBlocksFlag,
|
||||
utils.GpoPercentileFlag,
|
||||
utils.EWASMInterpreterFlag,
|
||||
utils.EVMInterpreterFlag,
|
||||
configFileFlag,
|
||||
}
|
||||
|
||||
|
@ -151,6 +153,7 @@ var (
|
|||
utils.WhisperEnabledFlag,
|
||||
utils.WhisperMaxMessageSizeFlag,
|
||||
utils.WhisperMinPOWFlag,
|
||||
utils.WhisperRestrictConnectionBetweenLightClientsFlag,
|
||||
}
|
||||
|
||||
metricsFlags = []cli.Flag{
|
||||
|
|
|
@ -207,6 +207,8 @@ var AppHelpFlagGroups = []flagGroup{
|
|||
Name: "VIRTUAL MACHINE",
|
||||
Flags: []cli.Flag{
|
||||
utils.VMEnableDebugFlag,
|
||||
utils.EVMInterpreterFlag,
|
||||
utils.EWASMInterpreterFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
@ -92,7 +92,7 @@ func (w *wizard) deployDashboard() {
|
|||
pages = append(pages, page)
|
||||
}
|
||||
}
|
||||
// Promt the user to chose one, enter manually or simply not list this service
|
||||
// Prompt the user to chose one, enter manually or simply not list this service
|
||||
defLabel, defChoice := "don't list", len(pages)+2
|
||||
if len(pages) > 0 {
|
||||
defLabel, defChoice = pages[0], 1
|
||||
|
|
|
@ -87,7 +87,7 @@ func (w *wizard) makeServer() string {
|
|||
return input
|
||||
}
|
||||
|
||||
// selectServer lists the user all the currnetly known servers to choose from,
|
||||
// selectServer lists the user all the currently known servers to choose from,
|
||||
// also granting the option to add a new one.
|
||||
func (w *wizard) selectServer() string {
|
||||
// List the available server to the user and wait for a choice
|
||||
|
@ -115,7 +115,7 @@ func (w *wizard) selectServer() string {
|
|||
// manageComponents displays a list of network components the user can tear down
|
||||
// and an option
|
||||
func (w *wizard) manageComponents() {
|
||||
// List all the componens we can tear down, along with an entry to deploy a new one
|
||||
// List all the components we can tear down, along with an entry to deploy a new one
|
||||
fmt.Println()
|
||||
|
||||
var serviceHosts, serviceNames []string
|
||||
|
|
|
@ -51,7 +51,7 @@ func accessNewPass(ctx *cli.Context) {
|
|||
password = getPassPhrase("", 0, makePasswordList(ctx))
|
||||
dryRun = ctx.Bool(SwarmDryRunFlag.Name)
|
||||
)
|
||||
accessKey, ae, err = api.DoPasswordNew(ctx, password, salt)
|
||||
accessKey, ae, err = api.DoPassword(ctx, password, salt)
|
||||
if err != nil {
|
||||
utils.Fatalf("error getting session key: %v", err)
|
||||
}
|
||||
|
@ -62,7 +62,6 @@ func accessNewPass(ctx *cli.Context) {
|
|||
utils.Fatalf("had an error printing the manifests: %v", err)
|
||||
}
|
||||
} else {
|
||||
utils.Fatalf("uploading manifests")
|
||||
err = uploadManifests(ctx, m, nil)
|
||||
if err != nil {
|
||||
utils.Fatalf("had an error uploading the manifests: %v", err)
|
||||
|
@ -85,7 +84,7 @@ func accessNewPK(ctx *cli.Context) {
|
|||
granteePublicKey = ctx.String(SwarmAccessGrantKeyFlag.Name)
|
||||
dryRun = ctx.Bool(SwarmDryRunFlag.Name)
|
||||
)
|
||||
sessionKey, ae, err = api.DoPKNew(ctx, privateKey, granteePublicKey, salt)
|
||||
sessionKey, ae, err = api.DoPK(ctx, privateKey, granteePublicKey, salt)
|
||||
if err != nil {
|
||||
utils.Fatalf("error getting session key: %v", err)
|
||||
}
|
||||
|
@ -110,23 +109,38 @@ func accessNewACT(ctx *cli.Context) {
|
|||
}
|
||||
|
||||
var (
|
||||
ae *api.AccessEntry
|
||||
actManifest *api.Manifest
|
||||
accessKey []byte
|
||||
err error
|
||||
ref = args[0]
|
||||
grantees = []string{}
|
||||
actFilename = ctx.String(SwarmAccessGrantKeysFlag.Name)
|
||||
privateKey = getPrivKey(ctx)
|
||||
dryRun = ctx.Bool(SwarmDryRunFlag.Name)
|
||||
ae *api.AccessEntry
|
||||
actManifest *api.Manifest
|
||||
accessKey []byte
|
||||
err error
|
||||
ref = args[0]
|
||||
pkGrantees = []string{}
|
||||
passGrantees = []string{}
|
||||
pkGranteesFilename = ctx.String(SwarmAccessGrantKeysFlag.Name)
|
||||
passGranteesFilename = ctx.String(utils.PasswordFileFlag.Name)
|
||||
privateKey = getPrivKey(ctx)
|
||||
dryRun = ctx.Bool(SwarmDryRunFlag.Name)
|
||||
)
|
||||
|
||||
bytes, err := ioutil.ReadFile(actFilename)
|
||||
if err != nil {
|
||||
utils.Fatalf("had an error reading the grantee public key list")
|
||||
if pkGranteesFilename == "" && passGranteesFilename == "" {
|
||||
utils.Fatalf("you have to provide either a grantee public-keys file or an encryption passwords file (or both)")
|
||||
}
|
||||
grantees = strings.Split(string(bytes), "\n")
|
||||
accessKey, ae, actManifest, err = api.DoACTNew(ctx, privateKey, salt, grantees)
|
||||
|
||||
if pkGranteesFilename != "" {
|
||||
bytes, err := ioutil.ReadFile(pkGranteesFilename)
|
||||
if err != nil {
|
||||
utils.Fatalf("had an error reading the grantee public key list")
|
||||
}
|
||||
pkGrantees = strings.Split(string(bytes), "\n")
|
||||
}
|
||||
|
||||
if passGranteesFilename != "" {
|
||||
bytes, err := ioutil.ReadFile(passGranteesFilename)
|
||||
if err != nil {
|
||||
utils.Fatalf("could not read password filename: %v", err)
|
||||
}
|
||||
passGrantees = strings.Split(string(bytes), "\n")
|
||||
}
|
||||
accessKey, ae, actManifest, err = api.DoACT(ctx, privateKey, salt, pkGrantees, passGrantees)
|
||||
if err != nil {
|
||||
utils.Fatalf("error generating ACT manifest: %v", err)
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func hash(ctx *cli.Context) {
|
|||
defer f.Close()
|
||||
|
||||
stat, _ := f.Stat()
|
||||
fileStore := storage.NewFileStore(storage.NewMapChunkStore(), storage.NewFileStoreParams())
|
||||
fileStore := storage.NewFileStore(&storage.FakeChunkStore{}, storage.NewFileStoreParams())
|
||||
addr, _, err := fileStore.Store(context.TODO(), f, stat.Size(), false)
|
||||
if err != nil {
|
||||
utils.Fatalf("%v\n", err)
|
||||
|
|
|
@ -18,6 +18,7 @@ package main
|
|||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -208,6 +209,10 @@ var (
|
|||
Name: "data",
|
||||
Usage: "Initializes the resource with the given hex-encoded data. Data must be prefixed by 0x",
|
||||
}
|
||||
SwarmCompressedFlag = cli.BoolFlag{
|
||||
Name: "compressed",
|
||||
Usage: "Prints encryption keys in compressed form",
|
||||
}
|
||||
)
|
||||
|
||||
//declare a few constant error messages, useful for later error check comparisons in test
|
||||
|
@ -252,6 +257,14 @@ func init() {
|
|||
Usage: "Print version numbers",
|
||||
Description: "The output of this command is supposed to be machine-readable",
|
||||
},
|
||||
{
|
||||
Action: keys,
|
||||
CustomHelpTemplate: helpTemplate,
|
||||
Name: "print-keys",
|
||||
Flags: []cli.Flag{SwarmCompressedFlag},
|
||||
Usage: "Print public key information",
|
||||
Description: "The output of this command is supposed to be machine-readable",
|
||||
},
|
||||
{
|
||||
Action: upload,
|
||||
CustomHelpTemplate: helpTemplate,
|
||||
|
@ -306,6 +319,7 @@ func init() {
|
|||
Flags: []cli.Flag{
|
||||
SwarmAccessGrantKeysFlag,
|
||||
SwarmDryRunFlag,
|
||||
utils.PasswordFileFlag,
|
||||
},
|
||||
Name: "act",
|
||||
Usage: "encrypts a reference with the node's private key and a given grantee's public key and embeds it into a root manifest",
|
||||
|
@ -580,6 +594,17 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func keys(ctx *cli.Context) error {
|
||||
privateKey := getPrivKey(ctx)
|
||||
pub := hex.EncodeToString(crypto.FromECDSAPub(&privateKey.PublicKey))
|
||||
pubCompressed := hex.EncodeToString(crypto.CompressPubkey(&privateKey.PublicKey))
|
||||
if !ctx.Bool(SwarmCompressedFlag.Name) {
|
||||
fmt.Println(fmt.Sprintf("publicKey=%s", pub))
|
||||
}
|
||||
fmt.Println(fmt.Sprintf("publicKeyCompressed=%s", pubCompressed))
|
||||
return nil
|
||||
}
|
||||
|
||||
func version(ctx *cli.Context) error {
|
||||
fmt.Println(strings.Title(clientIdentifier))
|
||||
fmt.Println("Version:", sv.VersionWithMeta)
|
||||
|
|
|
@ -48,7 +48,7 @@ func main() {
|
|||
cli.StringFlag{
|
||||
Name: "cluster-endpoint",
|
||||
Value: "testing",
|
||||
Usage: "cluster to point to (open, or testing)",
|
||||
Usage: "cluster to point to (local, open or testing)",
|
||||
Destination: &cluster,
|
||||
},
|
||||
cli.IntFlag{
|
||||
|
@ -76,8 +76,8 @@ func main() {
|
|||
},
|
||||
cli.IntFlag{
|
||||
Name: "filesize",
|
||||
Value: 1,
|
||||
Usage: "file size for generated random file in MB",
|
||||
Value: 1024,
|
||||
Usage: "file size for generated random file in KB",
|
||||
Destination: &filesize,
|
||||
},
|
||||
}
|
||||
|
|
18
vendor/github.com/ethereum/go-ethereum/cmd/swarm/swarm-smoke/upload_and_sync.go
generated
vendored
18
vendor/github.com/ethereum/go-ethereum/cmd/swarm/swarm-smoke/upload_and_sync.go
generated
vendored
|
@ -39,6 +39,11 @@ import (
|
|||
func generateEndpoints(scheme string, cluster string, from int, to int) {
|
||||
if cluster == "prod" {
|
||||
cluster = ""
|
||||
} else if cluster == "local" {
|
||||
for port := from; port <= to; port++ {
|
||||
endpoints = append(endpoints, fmt.Sprintf("%s://localhost:%v", scheme, port))
|
||||
}
|
||||
return
|
||||
} else {
|
||||
cluster = cluster + "."
|
||||
}
|
||||
|
@ -53,13 +58,13 @@ func generateEndpoints(scheme string, cluster string, from int, to int) {
|
|||
}
|
||||
|
||||
func cliUploadAndSync(c *cli.Context) error {
|
||||
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size", filesize) }(time.Now())
|
||||
defer func(now time.Time) { log.Info("total time", "time", time.Since(now), "size (kb)", filesize) }(time.Now())
|
||||
|
||||
generateEndpoints(scheme, cluster, from, to)
|
||||
|
||||
log.Info("uploading to " + endpoints[0] + " and syncing")
|
||||
|
||||
f, cleanup := generateRandomFile(filesize * 1000000)
|
||||
f, cleanup := generateRandomFile(filesize * 1000)
|
||||
defer cleanup()
|
||||
|
||||
hash, err := upload(f, endpoints[0])
|
||||
|
@ -76,12 +81,7 @@ func cliUploadAndSync(c *cli.Context) error {
|
|||
|
||||
log.Info("uploaded successfully", "hash", hash, "digest", fmt.Sprintf("%x", fhash))
|
||||
|
||||
if filesize < 10 {
|
||||
time.Sleep(35 * time.Second)
|
||||
} else {
|
||||
time.Sleep(15 * time.Second)
|
||||
time.Sleep(2 * time.Duration(filesize) * time.Second)
|
||||
}
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
for _, endpoint := range endpoints {
|
||||
|
@ -109,7 +109,7 @@ func cliUploadAndSync(c *cli.Context) error {
|
|||
// fetch is getting the requested `hash` from the `endpoint` and compares it with the `original` file
|
||||
func fetch(hash string, endpoint string, original []byte, ruid string) error {
|
||||
log.Trace("sleeping", "ruid", ruid)
|
||||
time.Sleep(5 * time.Second)
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
log.Trace("http get request", "ruid", ruid, "api", endpoint, "hash", hash)
|
||||
res, err := http.Get(endpoint + "/bzz:/" + hash + "/")
|
||||
|
|
|
@ -343,12 +343,12 @@ var (
|
|||
}
|
||||
MinerGasPriceFlag = BigFlag{
|
||||
Name: "miner.gasprice",
|
||||
Usage: "Minimal gas price for mining a transactions",
|
||||
Usage: "Minimum gas price for mining a transaction",
|
||||
Value: eth.DefaultConfig.MinerGasPrice,
|
||||
}
|
||||
MinerLegacyGasPriceFlag = BigFlag{
|
||||
Name: "gasprice",
|
||||
Usage: "Minimal gas price for mining a transactions (deprecated, use --miner.gasprice)",
|
||||
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
|
||||
Value: eth.DefaultConfig.MinerGasPrice,
|
||||
}
|
||||
MinerEtherbaseFlag = cli.StringFlag{
|
||||
|
@ -567,6 +567,10 @@ var (
|
|||
Usage: "Minimum POW accepted",
|
||||
Value: whisper.DefaultMinimumPoW,
|
||||
}
|
||||
WhisperRestrictConnectionBetweenLightClientsFlag = cli.BoolFlag{
|
||||
Name: "shh.restrict-light",
|
||||
Usage: "Restrict connection between two whisper light clients",
|
||||
}
|
||||
|
||||
// Metrics flags
|
||||
MetricsEnabledFlag = cli.BoolFlag{
|
||||
|
@ -606,6 +610,17 @@ var (
|
|||
Usage: "InfluxDB `host` tag attached to all measurements",
|
||||
Value: "localhost",
|
||||
}
|
||||
|
||||
EWASMInterpreterFlag = cli.StringFlag{
|
||||
Name: "vm.ewasm",
|
||||
Usage: "External ewasm configuration (default = built-in interpreter)",
|
||||
Value: "",
|
||||
}
|
||||
EVMInterpreterFlag = cli.StringFlag{
|
||||
Name: "vm.evm",
|
||||
Usage: "External EVM configuration (default = built-in interpreter)",
|
||||
Value: "",
|
||||
}
|
||||
)
|
||||
|
||||
// MakeDataDir retrieves the currently requested data directory, terminating
|
||||
|
@ -1099,6 +1114,9 @@ func SetShhConfig(ctx *cli.Context, stack *node.Node, cfg *whisper.Config) {
|
|||
if ctx.GlobalIsSet(WhisperMinPOWFlag.Name) {
|
||||
cfg.MinimumAcceptedPOW = ctx.GlobalFloat64(WhisperMinPOWFlag.Name)
|
||||
}
|
||||
if ctx.GlobalIsSet(WhisperRestrictConnectionBetweenLightClientsFlag.Name) {
|
||||
cfg.RestrictConnectionBetweenLightClients = true
|
||||
}
|
||||
}
|
||||
|
||||
// SetEthConfig applies eth-related command line flags to the config.
|
||||
|
@ -1177,6 +1195,14 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
|||
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
|
||||
}
|
||||
|
||||
if ctx.GlobalIsSet(EWASMInterpreterFlag.Name) {
|
||||
cfg.EWASMInterpreter = ctx.GlobalString(EWASMInterpreterFlag.Name)
|
||||
}
|
||||
|
||||
if ctx.GlobalIsSet(EVMInterpreterFlag.Name) {
|
||||
cfg.EVMInterpreter = ctx.GlobalString(EVMInterpreterFlag.Name)
|
||||
}
|
||||
|
||||
// Override any default configs for hard coded networks.
|
||||
switch {
|
||||
case ctx.GlobalBool(TestnetFlag.Name):
|
||||
|
@ -1372,7 +1398,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
|
|||
cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
|
||||
}
|
||||
vmcfg := vm.Config{EnablePreimageRecording: ctx.GlobalBool(VMEnableDebugFlag.Name)}
|
||||
chain, err = core.NewBlockChain(chainDb, cache, config, engine, vmcfg)
|
||||
chain, err = core.NewBlockChain(chainDb, cache, config, engine, vmcfg, nil)
|
||||
if err != nil {
|
||||
Fatalf("Can't create BlockChain: %v", err)
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
|
|||
return h[len(h)-flen:]
|
||||
}
|
||||
hh := make([]byte, flen)
|
||||
copy(hh[flen-len(h):flen], h[:])
|
||||
copy(hh[flen-len(h):flen], h)
|
||||
return hh
|
||||
}
|
||||
|
||||
|
|
|
@ -38,3 +38,45 @@ func (d PrettyDuration) String() string {
|
|||
}
|
||||
return label
|
||||
}
|
||||
|
||||
// PrettyAge is a pretty printed version of a time.Duration value that rounds
|
||||
// the values up to a single most significant unit, days/weeks/years included.
|
||||
type PrettyAge time.Time
|
||||
|
||||
// ageUnits is a list of units the age pretty printing uses.
|
||||
var ageUnits = []struct {
|
||||
Size time.Duration
|
||||
Symbol string
|
||||
}{
|
||||
{12 * 30 * 24 * time.Hour, "y"},
|
||||
{30 * 24 * time.Hour, "mo"},
|
||||
{7 * 24 * time.Hour, "w"},
|
||||
{24 * time.Hour, "d"},
|
||||
{time.Hour, "h"},
|
||||
{time.Minute, "m"},
|
||||
{time.Second, "s"},
|
||||
}
|
||||
|
||||
// String implements the Stringer interface, allowing pretty printing of duration
|
||||
// values rounded to the most significant time unit.
|
||||
func (t PrettyAge) String() string {
|
||||
// Calculate the time difference and handle the 0 cornercase
|
||||
diff := time.Since(time.Time(t))
|
||||
if diff < time.Second {
|
||||
return "0"
|
||||
}
|
||||
// Accumulate a precision of 3 components before returning
|
||||
result, prec := "", 0
|
||||
|
||||
for _, unit := range ageUnits {
|
||||
if diff > unit.Size {
|
||||
result = fmt.Sprintf("%s%d%s", result, diff/unit.Size, unit.Symbol)
|
||||
diff %= unit.Size
|
||||
|
||||
if prec += 1; prec >= 3 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import (
|
|||
const (
|
||||
// HashLength is the expected length of the hash
|
||||
HashLength = 32
|
||||
// AddressLength is the expected length of the adddress
|
||||
// AddressLength is the expected length of the address
|
||||
AddressLength = 20
|
||||
)
|
||||
|
||||
|
|
|
@ -93,27 +93,33 @@ var (
|
|||
|
||||
// errMissingSignature is returned if a block's extra-data section doesn't seem
|
||||
// to contain a 65 byte secp256k1 signature.
|
||||
errMissingSignature = errors.New("extra-data 65 byte suffix signature missing")
|
||||
errMissingSignature = errors.New("extra-data 65 byte signature suffix missing")
|
||||
|
||||
// errExtraSigners is returned if non-checkpoint block contain signer data in
|
||||
// their extra-data fields.
|
||||
errExtraSigners = errors.New("non-checkpoint block contains extra signer list")
|
||||
|
||||
// errInvalidCheckpointSigners is returned if a checkpoint block contains an
|
||||
// invalid list of signers (i.e. non divisible by 20 bytes, or not the correct
|
||||
// ones).
|
||||
// invalid list of signers (i.e. non divisible by 20 bytes).
|
||||
errInvalidCheckpointSigners = errors.New("invalid signer list on checkpoint block")
|
||||
|
||||
// errMismatchingCheckpointSigners is returned if a checkpoint block contains a
|
||||
// list of signers different than the one the local node calculated.
|
||||
errMismatchingCheckpointSigners = errors.New("mismatching signer list on checkpoint block")
|
||||
|
||||
// errInvalidMixDigest is returned if a block's mix digest is non-zero.
|
||||
errInvalidMixDigest = errors.New("non-zero mix digest")
|
||||
|
||||
// errInvalidUncleHash is returned if a block contains an non-empty uncle list.
|
||||
errInvalidUncleHash = errors.New("non empty uncle hash")
|
||||
|
||||
// errInvalidDifficulty is returned if the difficulty of a block is not either
|
||||
// of 1 or 2, or if the value does not match the turn of the signer.
|
||||
// errInvalidDifficulty is returned if the difficulty of a block neither 1 or 2.
|
||||
errInvalidDifficulty = errors.New("invalid difficulty")
|
||||
|
||||
// errWrongDifficulty is returned if the difficulty of a block doesn't match the
|
||||
// turn of the signer.
|
||||
errWrongDifficulty = errors.New("wrong difficulty")
|
||||
|
||||
// ErrInvalidTimestamp is returned if the timestamp of a block is lower than
|
||||
// the previous block's timestamp + the minimum block period.
|
||||
ErrInvalidTimestamp = errors.New("invalid timestamp")
|
||||
|
@ -122,13 +128,12 @@ var (
|
|||
// be modified via out-of-range or non-contiguous headers.
|
||||
errInvalidVotingChain = errors.New("invalid voting chain")
|
||||
|
||||
// errUnauthorized is returned if a header is signed by a non-authorized entity.
|
||||
errUnauthorized = errors.New("unauthorized")
|
||||
// errUnauthorizedSigner is returned if a header is signed by a non-authorized entity.
|
||||
errUnauthorizedSigner = errors.New("unauthorized signer")
|
||||
|
||||
// errWaitTransactions is returned if an empty block is attempted to be sealed
|
||||
// on an instant chain (0 second period). It's important to refuse these as the
|
||||
// block reward is zero, so an empty block just bloats the chain... fast.
|
||||
errWaitTransactions = errors.New("waiting for transactions")
|
||||
// errRecentlySigned is returned if a header is signed by an authorized entity
|
||||
// that already signed a header recently, thus is temporarily not allowed to.
|
||||
errRecentlySigned = errors.New("recently signed")
|
||||
)
|
||||
|
||||
// SignerFn is a signer callback function to request a hash to be signed by a
|
||||
|
@ -205,6 +210,9 @@ type Clique struct {
|
|||
signer common.Address // Ethereum address of the signing key
|
||||
signFn SignerFn // Signer function to authorize hashes with
|
||||
lock sync.RWMutex // Protects the signer fields
|
||||
|
||||
// The fields below are for testing only
|
||||
fakeDiff bool // Skip difficulty verifications
|
||||
}
|
||||
|
||||
// New creates a Clique proof-of-authority consensus engine with the initial
|
||||
|
@ -359,7 +367,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
|
|||
}
|
||||
extraSuffix := len(header.Extra) - extraSeal
|
||||
if !bytes.Equal(header.Extra[extraVanity:extraSuffix], signers) {
|
||||
return errInvalidCheckpointSigners
|
||||
return errMismatchingCheckpointSigners
|
||||
}
|
||||
}
|
||||
// All basic checks passed, verify the seal and return
|
||||
|
@ -388,7 +396,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
|
|||
}
|
||||
}
|
||||
// If we're at an checkpoint block, make a snapshot if it's known
|
||||
if number%c.config.Epoch == 0 {
|
||||
if number == 0 || (number%c.config.Epoch == 0 && chain.GetHeaderByNumber(number-1) == nil) {
|
||||
checkpoint := chain.GetHeaderByNumber(number)
|
||||
if checkpoint != nil {
|
||||
hash := checkpoint.Hash()
|
||||
|
@ -481,23 +489,25 @@ func (c *Clique) verifySeal(chain consensus.ChainReader, header *types.Header, p
|
|||
return err
|
||||
}
|
||||
if _, ok := snap.Signers[signer]; !ok {
|
||||
return errUnauthorized
|
||||
return errUnauthorizedSigner
|
||||
}
|
||||
for seen, recent := range snap.Recents {
|
||||
if recent == signer {
|
||||
// Signer is among recents, only fail if the current block doesn't shift it out
|
||||
if limit := uint64(len(snap.Signers)/2 + 1); seen > number-limit {
|
||||
return errUnauthorized
|
||||
return errRecentlySigned
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ensure that the difficulty corresponds to the turn-ness of the signer
|
||||
inturn := snap.inturn(header.Number.Uint64(), signer)
|
||||
if inturn && header.Difficulty.Cmp(diffInTurn) != 0 {
|
||||
return errInvalidDifficulty
|
||||
}
|
||||
if !inturn && header.Difficulty.Cmp(diffNoTurn) != 0 {
|
||||
return errInvalidDifficulty
|
||||
if !c.fakeDiff {
|
||||
inturn := snap.inturn(header.Number.Uint64(), signer)
|
||||
if inturn && header.Difficulty.Cmp(diffInTurn) != 0 {
|
||||
return errWrongDifficulty
|
||||
}
|
||||
if !inturn && header.Difficulty.Cmp(diffNoTurn) != 0 {
|
||||
return errWrongDifficulty
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -600,7 +610,8 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
|
|||
}
|
||||
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
|
||||
if c.config.Period == 0 && len(block.Transactions()) == 0 {
|
||||
return errWaitTransactions
|
||||
log.Info("Sealing paused, waiting for transactions")
|
||||
return nil
|
||||
}
|
||||
// Don't hold the signer fields for the entire sealing procedure
|
||||
c.lock.RLock()
|
||||
|
@ -613,7 +624,7 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, results c
|
|||
return err
|
||||
}
|
||||
if _, authorized := snap.Signers[signer]; !authorized {
|
||||
return errUnauthorized
|
||||
return errUnauthorizedSigner
|
||||
}
|
||||
// If we're amongst the recent signers, wait for the next block
|
||||
for seen, recent := range snap.Recents {
|
||||
|
|
|
@ -57,12 +57,12 @@ type Snapshot struct {
|
|||
Tally map[common.Address]Tally `json:"tally"` // Current vote tally to avoid recalculating
|
||||
}
|
||||
|
||||
// signers implements the sort interface to allow sorting a list of addresses
|
||||
type signers []common.Address
|
||||
// signersAscending implements the sort interface to allow sorting a list of addresses
|
||||
type signersAscending []common.Address
|
||||
|
||||
func (s signers) Len() int { return len(s) }
|
||||
func (s signers) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 }
|
||||
func (s signers) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s signersAscending) Len() int { return len(s) }
|
||||
func (s signersAscending) Less(i, j int) bool { return bytes.Compare(s[i][:], s[j][:]) < 0 }
|
||||
func (s signersAscending) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// newSnapshot creates a new snapshot with the specified startup parameters. This
|
||||
// method does not initialize the set of recent signers, so only ever use if for
|
||||
|
@ -214,11 +214,11 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
|
|||
return nil, err
|
||||
}
|
||||
if _, ok := snap.Signers[signer]; !ok {
|
||||
return nil, errUnauthorized
|
||||
return nil, errUnauthorizedSigner
|
||||
}
|
||||
for _, recent := range snap.Recents {
|
||||
if recent == signer {
|
||||
return nil, errUnauthorized
|
||||
return nil, errRecentlySigned
|
||||
}
|
||||
}
|
||||
snap.Recents[number] = signer
|
||||
|
@ -298,7 +298,7 @@ func (s *Snapshot) signers() []common.Address {
|
|||
for sig := range s.Signers {
|
||||
sigs = append(sigs, sig)
|
||||
}
|
||||
sort.Sort(signers(sigs))
|
||||
sort.Sort(signersAscending(sigs))
|
||||
return sigs
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ type Engine interface {
|
|||
// the result into the given channel.
|
||||
//
|
||||
// Note, the method returns immediately and will send the result async. More
|
||||
// than one result may also be returned depending on the consensus algorothm.
|
||||
// than one result may also be returned depending on the consensus algorithm.
|
||||
Seal(chain ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
|
||||
|
||||
// SealHash returns the hash of a block prior to it being sealed.
|
||||
|
|
|
@ -38,10 +38,24 @@ 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
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
// calcDifficultyConstantinople is the difficulty adjustment algorithm for Constantinople.
|
||||
// It returns the difficulty that a new block should have when created at time given the
|
||||
// parent block's time and difficulty. The calculation uses the Byzantium rules, but with
|
||||
// bomb offset 5M.
|
||||
// Specification EIP-1234: https://eips.ethereum.org/EIPS/eip-1234
|
||||
calcDifficultyConstantinople = makeDifficultyCalculator(big.NewInt(5000000))
|
||||
|
||||
// calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
|
||||
// the difficulty that a new block should have when created at time given the
|
||||
// parent block's time and difficulty. The calculation uses the Byzantium rules.
|
||||
// Specification EIP-649: https://eips.ethereum.org/EIPS/eip-649
|
||||
calcDifficultyByzantium = makeDifficultyCalculator(big.NewInt(3000000))
|
||||
)
|
||||
|
||||
// Various error messages to mark blocks invalid. These should be private to
|
||||
|
@ -299,6 +313,8 @@ func (ethash *Ethash) CalcDifficulty(chain consensus.ChainReader, time uint64, p
|
|||
func CalcDifficulty(config *params.ChainConfig, time uint64, parent *types.Header) *big.Int {
|
||||
next := new(big.Int).Add(parent.Number, big1)
|
||||
switch {
|
||||
case config.IsConstantinople(next):
|
||||
return calcDifficultyConstantinople(time, parent)
|
||||
case config.IsByzantium(next):
|
||||
return calcDifficultyByzantium(time, parent)
|
||||
case config.IsHomestead(next):
|
||||
|
@ -316,66 +332,69 @@ var (
|
|||
big9 = big.NewInt(9)
|
||||
big10 = big.NewInt(10)
|
||||
bigMinus99 = big.NewInt(-99)
|
||||
big2999999 = big.NewInt(2999999)
|
||||
)
|
||||
|
||||
// calcDifficultyByzantium is the difficulty adjustment algorithm. It returns
|
||||
// the difficulty that a new block should have when created at time given the
|
||||
// parent block's time and difficulty. The calculation uses the Byzantium rules.
|
||||
func calcDifficultyByzantium(time uint64, parent *types.Header) *big.Int {
|
||||
// https://github.com/ethereum/EIPs/issues/100.
|
||||
// algorithm:
|
||||
// diff = (parent_diff +
|
||||
// (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
|
||||
// ) + 2^(periodCount - 2)
|
||||
// makeDifficultyCalculator creates a difficultyCalculator with the given bomb-delay.
|
||||
// the difficulty is calculated with Byzantium rules, which differs from Homestead in
|
||||
// how uncles affect the calculation
|
||||
func makeDifficultyCalculator(bombDelay *big.Int) func(time uint64, parent *types.Header) *big.Int {
|
||||
// Note, the calculations below looks at the parent number, which is 1 below
|
||||
// the block number. Thus we remove one from the delay given
|
||||
bombDelayFromParent := new(big.Int).Sub(bombDelay, big1)
|
||||
return func(time uint64, parent *types.Header) *big.Int {
|
||||
// https://github.com/ethereum/EIPs/issues/100.
|
||||
// algorithm:
|
||||
// diff = (parent_diff +
|
||||
// (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
|
||||
// ) + 2^(periodCount - 2)
|
||||
|
||||
bigTime := new(big.Int).SetUint64(time)
|
||||
bigParentTime := new(big.Int).Set(parent.Time)
|
||||
bigTime := new(big.Int).SetUint64(time)
|
||||
bigParentTime := new(big.Int).Set(parent.Time)
|
||||
|
||||
// holds intermediate values to make the algo easier to read & audit
|
||||
x := new(big.Int)
|
||||
y := new(big.Int)
|
||||
// holds intermediate values to make the algo easier to read & audit
|
||||
x := new(big.Int)
|
||||
y := new(big.Int)
|
||||
|
||||
// (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9
|
||||
x.Sub(bigTime, bigParentTime)
|
||||
x.Div(x, big9)
|
||||
if parent.UncleHash == types.EmptyUncleHash {
|
||||
x.Sub(big1, x)
|
||||
} else {
|
||||
x.Sub(big2, x)
|
||||
}
|
||||
// max((2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9, -99)
|
||||
if x.Cmp(bigMinus99) < 0 {
|
||||
x.Set(bigMinus99)
|
||||
}
|
||||
// parent_diff + (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
|
||||
y.Div(parent.Difficulty, params.DifficultyBoundDivisor)
|
||||
x.Mul(y, x)
|
||||
x.Add(parent.Difficulty, x)
|
||||
// (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9
|
||||
x.Sub(bigTime, bigParentTime)
|
||||
x.Div(x, big9)
|
||||
if parent.UncleHash == types.EmptyUncleHash {
|
||||
x.Sub(big1, x)
|
||||
} else {
|
||||
x.Sub(big2, x)
|
||||
}
|
||||
// max((2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) // 9, -99)
|
||||
if x.Cmp(bigMinus99) < 0 {
|
||||
x.Set(bigMinus99)
|
||||
}
|
||||
// parent_diff + (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99))
|
||||
y.Div(parent.Difficulty, params.DifficultyBoundDivisor)
|
||||
x.Mul(y, x)
|
||||
x.Add(parent.Difficulty, x)
|
||||
|
||||
// minimum difficulty can ever be (before exponential factor)
|
||||
if x.Cmp(params.MinimumDifficulty) < 0 {
|
||||
x.Set(params.MinimumDifficulty)
|
||||
}
|
||||
// calculate a fake block number for the ice-age delay:
|
||||
// https://github.com/ethereum/EIPs/pull/669
|
||||
// fake_block_number = max(0, block.number - 3_000_000)
|
||||
fakeBlockNumber := new(big.Int)
|
||||
if parent.Number.Cmp(big2999999) >= 0 {
|
||||
fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, big2999999) // Note, parent is 1 less than the actual block number
|
||||
}
|
||||
// for the exponential factor
|
||||
periodCount := fakeBlockNumber
|
||||
periodCount.Div(periodCount, expDiffPeriod)
|
||||
// minimum difficulty can ever be (before exponential factor)
|
||||
if x.Cmp(params.MinimumDifficulty) < 0 {
|
||||
x.Set(params.MinimumDifficulty)
|
||||
}
|
||||
// calculate a fake block number for the ice-age delay
|
||||
// Specification: https://eips.ethereum.org/EIPS/eip-1234
|
||||
fakeBlockNumber := new(big.Int)
|
||||
if parent.Number.Cmp(bombDelayFromParent) >= 0 {
|
||||
fakeBlockNumber = fakeBlockNumber.Sub(parent.Number, bombDelayFromParent)
|
||||
}
|
||||
// for the exponential factor
|
||||
periodCount := fakeBlockNumber
|
||||
periodCount.Div(periodCount, expDiffPeriod)
|
||||
|
||||
// the exponential factor, commonly referred to as "the bomb"
|
||||
// diff = diff + 2^(periodCount - 2)
|
||||
if periodCount.Cmp(big1) > 0 {
|
||||
y.Sub(periodCount, big2)
|
||||
y.Exp(big2, y, nil)
|
||||
x.Add(x, y)
|
||||
// the exponential factor, commonly referred to as "the bomb"
|
||||
// diff = diff + 2^(periodCount - 2)
|
||||
if periodCount.Cmp(big1) > 0 {
|
||||
y.Sub(periodCount, big2)
|
||||
y.Exp(big2, y, nil)
|
||||
x.Add(x, y)
|
||||
}
|
||||
return x
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
// calcDifficultyHomestead is the difficulty adjustment algorithm. It returns
|
||||
|
@ -592,6 +611,9 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
|||
if config.IsByzantium(header.Number) {
|
||||
blockReward = ByzantiumBlockReward
|
||||
}
|
||||
if config.IsConstantinople(header.Number) {
|
||||
blockReward = ConstantinopleBlockReward
|
||||
}
|
||||
// Accumulate the rewards for the miner and any included uncles
|
||||
reward := new(big.Int).Set(blockReward)
|
||||
r := new(big.Int)
|
||||
|
|
|
@ -485,7 +485,7 @@ func New(config Config, notify []string, noverify bool) *Ethash {
|
|||
caches: newlru("cache", config.CachesInMem, newCache),
|
||||
datasets: newlru("dataset", config.DatasetsInMem, newDataset),
|
||||
update: make(chan struct{}),
|
||||
hashrate: metrics.NewMeter(),
|
||||
hashrate: metrics.NewMeterForced(),
|
||||
workCh: make(chan *sealTask),
|
||||
fetchWorkCh: make(chan *sealWork),
|
||||
submitWorkCh: make(chan *mineResult),
|
||||
|
@ -505,7 +505,7 @@ func NewTester(notify []string, noverify bool) *Ethash {
|
|||
caches: newlru("cache", 1, newCache),
|
||||
datasets: newlru("dataset", 1, newDataset),
|
||||
update: make(chan struct{}),
|
||||
hashrate: metrics.NewMeter(),
|
||||
hashrate: metrics.NewMeterForced(),
|
||||
workCh: make(chan *sealTask),
|
||||
fetchWorkCh: make(chan *sealWork),
|
||||
submitWorkCh: make(chan *mineResult),
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/mclock"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
|
@ -43,7 +44,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rlp"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/hashicorp/golang-lru"
|
||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -128,13 +128,14 @@ type BlockChain struct {
|
|||
validator Validator // block and state validator interface
|
||||
vmConfig vm.Config
|
||||
|
||||
badBlocks *lru.Cache // Bad block cache
|
||||
badBlocks *lru.Cache // Bad block cache
|
||||
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
|
||||
}
|
||||
|
||||
// NewBlockChain returns a fully initialised block chain using information
|
||||
// available in the database. It initialises the default Ethereum Validator and
|
||||
// Processor.
|
||||
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) {
|
||||
func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(block *types.Block) bool) (*BlockChain, error) {
|
||||
if cacheConfig == nil {
|
||||
cacheConfig = &CacheConfig{
|
||||
TrieNodeLimit: 256 * 1024 * 1024,
|
||||
|
@ -148,19 +149,20 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
|
|||
badBlocks, _ := lru.New(badBlockLimit)
|
||||
|
||||
bc := &BlockChain{
|
||||
chainConfig: chainConfig,
|
||||
cacheConfig: cacheConfig,
|
||||
db: db,
|
||||
triegc: prque.New(),
|
||||
stateCache: state.NewDatabase(db),
|
||||
quit: make(chan struct{}),
|
||||
bodyCache: bodyCache,
|
||||
bodyRLPCache: bodyRLPCache,
|
||||
blockCache: blockCache,
|
||||
futureBlocks: futureBlocks,
|
||||
engine: engine,
|
||||
vmConfig: vmConfig,
|
||||
badBlocks: badBlocks,
|
||||
chainConfig: chainConfig,
|
||||
cacheConfig: cacheConfig,
|
||||
db: db,
|
||||
triegc: prque.New(nil),
|
||||
stateCache: state.NewDatabase(db),
|
||||
quit: make(chan struct{}),
|
||||
shouldPreserve: shouldPreserve,
|
||||
bodyCache: bodyCache,
|
||||
bodyRLPCache: bodyRLPCache,
|
||||
blockCache: blockCache,
|
||||
futureBlocks: futureBlocks,
|
||||
engine: engine,
|
||||
vmConfig: vmConfig,
|
||||
badBlocks: badBlocks,
|
||||
}
|
||||
bc.SetValidator(NewBlockValidator(chainConfig, bc, engine))
|
||||
bc.SetProcessor(NewStateProcessor(chainConfig, bc, engine))
|
||||
|
@ -251,9 +253,9 @@ func (bc *BlockChain) loadLastState() error {
|
|||
blockTd := bc.GetTd(currentBlock.Hash(), currentBlock.NumberU64())
|
||||
fastTd := bc.GetTd(currentFastBlock.Hash(), currentFastBlock.NumberU64())
|
||||
|
||||
log.Info("Loaded most recent local header", "number", currentHeader.Number, "hash", currentHeader.Hash(), "td", headerTd)
|
||||
log.Info("Loaded most recent local full block", "number", currentBlock.Number(), "hash", currentBlock.Hash(), "td", blockTd)
|
||||
log.Info("Loaded most recent local fast block", "number", currentFastBlock.Number(), "hash", currentFastBlock.Hash(), "td", fastTd)
|
||||
log.Info("Loaded most recent local header", "number", currentHeader.Number, "hash", currentHeader.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(currentHeader.Time.Int64(), 0)))
|
||||
log.Info("Loaded most recent local full block", "number", currentBlock.Number(), "hash", currentBlock.Hash(), "td", blockTd, "age", common.PrettyAge(time.Unix(currentBlock.Time().Int64(), 0)))
|
||||
log.Info("Loaded most recent local fast block", "number", currentFastBlock.Number(), "hash", currentFastBlock.Hash(), "td", fastTd, "age", common.PrettyAge(time.Unix(currentFastBlock.Time().Int64(), 0)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -850,13 +852,16 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
|||
}
|
||||
bc.mu.Unlock()
|
||||
|
||||
log.Info("Imported new block receipts",
|
||||
"count", stats.processed,
|
||||
"elapsed", common.PrettyDuration(time.Since(start)),
|
||||
"number", head.Number(),
|
||||
"hash", head.Hash(),
|
||||
context := []interface{}{
|
||||
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
||||
"number", head.Number(), "hash", head.Hash(), "age", common.PrettyAge(time.Unix(head.Time().Int64(), 0)),
|
||||
"size", common.StorageSize(bytes),
|
||||
"ignored", stats.ignored)
|
||||
}
|
||||
if stats.ignored > 0 {
|
||||
context = append(context, []interface{}{"ignored", stats.ignored}...)
|
||||
}
|
||||
log.Info("Imported new block receipts", context...)
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
|
@ -915,7 +920,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
|||
} else {
|
||||
// Full but not archive node, do proper garbage collection
|
||||
triedb.Reference(root, common.Hash{}) // metadata reference to keep trie alive
|
||||
bc.triegc.Push(root, -float32(block.NumberU64()))
|
||||
bc.triegc.Push(root, -int64(block.NumberU64()))
|
||||
|
||||
if current := block.NumberU64(); current > triesInMemory {
|
||||
// If we exceeded our memory allowance, flush matured singleton nodes to disk
|
||||
|
@ -964,8 +969,17 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
|
|||
reorg := externTd.Cmp(localTd) > 0
|
||||
currentBlock = bc.CurrentBlock()
|
||||
if !reorg && externTd.Cmp(localTd) == 0 {
|
||||
// Split same-difficulty blocks by number, then at random
|
||||
reorg = block.NumberU64() < currentBlock.NumberU64() || (block.NumberU64() == currentBlock.NumberU64() && mrand.Float64() < 0.5)
|
||||
// Split same-difficulty blocks by number, then preferentially select
|
||||
// the block generated by the local miner as the canonical block.
|
||||
if block.NumberU64() < currentBlock.NumberU64() {
|
||||
reorg = true
|
||||
} else if block.NumberU64() == currentBlock.NumberU64() {
|
||||
var currentPreserve, blockPreserve bool
|
||||
if bc.shouldPreserve != nil {
|
||||
currentPreserve, blockPreserve = bc.shouldPreserve(currentBlock), bc.shouldPreserve(block)
|
||||
}
|
||||
reorg = !currentPreserve && (blockPreserve || mrand.Float64() < 0.5)
|
||||
}
|
||||
}
|
||||
if reorg {
|
||||
// Reorganise the chain if the parent is not the head block
|
||||
|
@ -1229,8 +1243,13 @@ func (st *insertStats) report(chain []*types.Block, index int, cache common.Stor
|
|||
context := []interface{}{
|
||||
"blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000,
|
||||
"elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed),
|
||||
"number", end.Number(), "hash", end.Hash(), "cache", cache,
|
||||
"number", end.Number(), "hash", end.Hash(),
|
||||
}
|
||||
if timestamp := time.Unix(end.Time().Int64(), 0); time.Since(timestamp) > time.Minute {
|
||||
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
||||
}
|
||||
context = append(context, []interface{}{"cache", cache}...)
|
||||
|
||||
if st.queued > 0 {
|
||||
context = append(context, []interface{}{"queued", st.queued}...)
|
||||
}
|
||||
|
|
|
@ -445,7 +445,7 @@ func (c *ChainIndexer) AddChildIndexer(indexer *ChainIndexer) {
|
|||
func (c *ChainIndexer) loadValidSections() {
|
||||
data, _ := c.indexDb.Get([]byte("count"))
|
||||
if len(data) == 8 {
|
||||
c.storedSections = binary.BigEndian.Uint64(data[:])
|
||||
c.storedSections = binary.BigEndian.Uint64(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,11 @@ func (b *BlockGen) SetExtra(data []byte) {
|
|||
b.header.Extra = data
|
||||
}
|
||||
|
||||
// SetNonce sets the nonce field of the generated block.
|
||||
func (b *BlockGen) SetNonce(nonce types.BlockNonce) {
|
||||
b.header.Nonce = nonce
|
||||
}
|
||||
|
||||
// AddTx adds a transaction to the generated block. If no coinbase has
|
||||
// been set, the block's coinbase is set to the zero address.
|
||||
//
|
||||
|
@ -172,7 +177,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
|||
genblock := func(i int, parent *types.Block, statedb *state.StateDB) (*types.Block, types.Receipts) {
|
||||
// TODO(karalabe): This is needed for clique, which depends on multiple blocks.
|
||||
// It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow.
|
||||
blockchain, _ := NewBlockChain(db, nil, config, engine, vm.Config{})
|
||||
blockchain, _ := NewBlockChain(db, nil, config, engine, vm.Config{}, nil)
|
||||
defer blockchain.Stop()
|
||||
|
||||
b := &BlockGen{i: i, parent: parent, chain: blocks, chainReader: blockchain, statedb: statedb, config: config, engine: engine}
|
||||
|
@ -190,13 +195,14 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
|
|||
if config.DAOForkSupport && config.DAOForkBlock != nil && config.DAOForkBlock.Cmp(b.header.Number) == 0 {
|
||||
misc.ApplyDAOHardFork(statedb)
|
||||
}
|
||||
// Execute any user modifications to the block and finalize it
|
||||
// Execute any user modifications to the block
|
||||
if gen != nil {
|
||||
gen(i, b)
|
||||
}
|
||||
|
||||
if b.engine != nil {
|
||||
// Finalize and seal the block
|
||||
block, _ := b.engine.Finalize(b.chainReader, b.header, statedb, b.txs, b.uncles, b.receipts)
|
||||
|
||||
// Write state changes to db
|
||||
root, err := statedb.Commit(config.IsEIP158(b.header.Number))
|
||||
if err != nil {
|
||||
|
|
|
@ -355,7 +355,7 @@ func DeveloperGenesisBlock(period uint64, faucet common.Address) *Genesis {
|
|||
common.BytesToAddress([]byte{6}): {Balance: big.NewInt(1)}, // ECAdd
|
||||
common.BytesToAddress([]byte{7}): {Balance: big.NewInt(1)}, // ECScalarMul
|
||||
common.BytesToAddress([]byte{8}): {Balance: big.NewInt(1)}, // ECPairing
|
||||
faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
|
||||
faucet: {Balance: new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(9))},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -281,8 +281,18 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
|
|||
}
|
||||
// Report some public statistics so the user has a clue what's going on
|
||||
last := chain[len(chain)-1]
|
||||
log.Info("Imported new block headers", "count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
||||
"number", last.Number, "hash", last.Hash(), "ignored", stats.ignored)
|
||||
|
||||
context := []interface{}{
|
||||
"count", stats.processed, "elapsed", common.PrettyDuration(time.Since(start)),
|
||||
"number", last.Number, "hash", last.Hash(),
|
||||
}
|
||||
if timestamp := time.Unix(last.Time.Int64(), 0); time.Since(timestamp) > time.Minute {
|
||||
context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...)
|
||||
}
|
||||
if stats.ignored > 0 {
|
||||
context = append(context, []interface{}{"ignored", stats.ignored}...)
|
||||
}
|
||||
log.Info("Imported new block headers", context...)
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ type stateObject struct {
|
|||
trie Trie // storage trie, which becomes non-nil on first access
|
||||
code Code // contract bytecode, which gets set when code is loaded
|
||||
|
||||
cachedStorage Storage // Storage entry cache to avoid duplicate reads
|
||||
originStorage Storage // Storage cache of original entries to dedup rewrites
|
||||
dirtyStorage Storage // Storage entries that need to be flushed to disk
|
||||
|
||||
// Cache flags.
|
||||
|
@ -115,7 +115,7 @@ func newObject(db *StateDB, address common.Address, data Account) *stateObject {
|
|||
address: address,
|
||||
addrHash: crypto.Keccak256Hash(address[:]),
|
||||
data: data,
|
||||
cachedStorage: make(Storage),
|
||||
originStorage: make(Storage),
|
||||
dirtyStorage: make(Storage),
|
||||
}
|
||||
}
|
||||
|
@ -159,13 +159,25 @@ func (c *stateObject) getTrie(db Database) Trie {
|
|||
return c.trie
|
||||
}
|
||||
|
||||
// GetState returns a value in account storage.
|
||||
// GetState retrieves a value from the account storage trie.
|
||||
func (self *stateObject) GetState(db Database, key common.Hash) common.Hash {
|
||||
value, exists := self.cachedStorage[key]
|
||||
if exists {
|
||||
// If we have a dirty value for this state entry, return it
|
||||
value, dirty := self.dirtyStorage[key]
|
||||
if dirty {
|
||||
return value
|
||||
}
|
||||
// Load from DB in case it is missing.
|
||||
// Otherwise return the entry's original value
|
||||
return self.GetCommittedState(db, key)
|
||||
}
|
||||
|
||||
// GetCommittedState retrieves a value from the committed account storage trie.
|
||||
func (self *stateObject) GetCommittedState(db Database, key common.Hash) common.Hash {
|
||||
// If we have the original value cached, return that
|
||||
value, cached := self.originStorage[key]
|
||||
if cached {
|
||||
return value
|
||||
}
|
||||
// Otherwise load the value from the database
|
||||
enc, err := self.getTrie(db).TryGet(key[:])
|
||||
if err != nil {
|
||||
self.setError(err)
|
||||
|
@ -178,22 +190,27 @@ func (self *stateObject) GetState(db Database, key common.Hash) common.Hash {
|
|||
}
|
||||
value.SetBytes(content)
|
||||
}
|
||||
self.cachedStorage[key] = value
|
||||
self.originStorage[key] = value
|
||||
return value
|
||||
}
|
||||
|
||||
// SetState updates a value in account storage.
|
||||
func (self *stateObject) SetState(db Database, key, value common.Hash) {
|
||||
// If the new value is the same as old, don't set
|
||||
prev := self.GetState(db, key)
|
||||
if prev == value {
|
||||
return
|
||||
}
|
||||
// New value is different, update and journal the change
|
||||
self.db.journal.append(storageChange{
|
||||
account: &self.address,
|
||||
key: key,
|
||||
prevalue: self.GetState(db, key),
|
||||
prevalue: prev,
|
||||
})
|
||||
self.setState(key, value)
|
||||
}
|
||||
|
||||
func (self *stateObject) setState(key, value common.Hash) {
|
||||
self.cachedStorage[key] = value
|
||||
self.dirtyStorage[key] = value
|
||||
}
|
||||
|
||||
|
@ -202,6 +219,13 @@ func (self *stateObject) updateTrie(db Database) Trie {
|
|||
tr := self.getTrie(db)
|
||||
for key, value := range self.dirtyStorage {
|
||||
delete(self.dirtyStorage, key)
|
||||
|
||||
// Skip noop changes, persist actual changes
|
||||
if value == self.originStorage[key] {
|
||||
continue
|
||||
}
|
||||
self.originStorage[key] = value
|
||||
|
||||
if (value == common.Hash{}) {
|
||||
self.setError(tr.TryDelete(key[:]))
|
||||
continue
|
||||
|
@ -279,7 +303,7 @@ func (self *stateObject) deepCopy(db *StateDB) *stateObject {
|
|||
}
|
||||
stateObject.code = self.code
|
||||
stateObject.dirtyStorage = self.dirtyStorage.Copy()
|
||||
stateObject.cachedStorage = self.dirtyStorage.Copy()
|
||||
stateObject.originStorage = self.originStorage.Copy()
|
||||
stateObject.suicided = self.suicided
|
||||
stateObject.dirtyCode = self.dirtyCode
|
||||
stateObject.deleted = self.deleted
|
||||
|
|
|
@ -169,11 +169,22 @@ func (self *StateDB) Preimages() map[common.Hash][]byte {
|
|||
return self.preimages
|
||||
}
|
||||
|
||||
// AddRefund adds gas to the refund counter
|
||||
func (self *StateDB) AddRefund(gas uint64) {
|
||||
self.journal.append(refundChange{prev: self.refund})
|
||||
self.refund += gas
|
||||
}
|
||||
|
||||
// SubRefund removes gas from the refund counter.
|
||||
// This method will panic if the refund counter goes below zero
|
||||
func (self *StateDB) SubRefund(gas uint64) {
|
||||
self.journal.append(refundChange{prev: self.refund})
|
||||
if gas > self.refund {
|
||||
panic("Refund counter below zero")
|
||||
}
|
||||
self.refund -= gas
|
||||
}
|
||||
|
||||
// Exist reports whether the given account address exists in the state.
|
||||
// Notably this also returns true for suicided accounts.
|
||||
func (self *StateDB) Exist(addr common.Address) bool {
|
||||
|
@ -236,10 +247,20 @@ func (self *StateDB) GetCodeHash(addr common.Address) common.Hash {
|
|||
return common.BytesToHash(stateObject.CodeHash())
|
||||
}
|
||||
|
||||
func (self *StateDB) GetState(addr common.Address, bhash common.Hash) common.Hash {
|
||||
// GetState retrieves a value from the given account's storage trie.
|
||||
func (self *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
|
||||
stateObject := self.getStateObject(addr)
|
||||
if stateObject != nil {
|
||||
return stateObject.GetState(self.db, bhash)
|
||||
return stateObject.GetState(self.db, hash)
|
||||
}
|
||||
return common.Hash{}
|
||||
}
|
||||
|
||||
// GetCommittedState retrieves a value from the given account's committed storage trie.
|
||||
func (self *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash {
|
||||
stateObject := self.getStateObject(addr)
|
||||
if stateObject != nil {
|
||||
return stateObject.GetCommittedState(self.db, hash)
|
||||
}
|
||||
return common.Hash{}
|
||||
}
|
||||
|
@ -435,19 +456,14 @@ func (db *StateDB) ForEachStorage(addr common.Address, cb func(key, value common
|
|||
if so == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// When iterating over the storage check the cache first
|
||||
for h, value := range so.cachedStorage {
|
||||
cb(h, value)
|
||||
}
|
||||
|
||||
it := trie.NewIterator(so.getTrie(db.db).NodeIterator(nil))
|
||||
for it.Next() {
|
||||
// ignore cached values
|
||||
key := common.BytesToHash(db.trie.GetKey(it.Key))
|
||||
if _, ok := so.cachedStorage[key]; !ok {
|
||||
cb(key, common.BytesToHash(it.Value))
|
||||
if value, dirty := so.dirtyStorage[key]; dirty {
|
||||
cb(key, value)
|
||||
continue
|
||||
}
|
||||
cb(key, common.BytesToHash(it.Value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
|
|||
*usedGas += gas
|
||||
|
||||
// Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
|
||||
// based on the eip phase, we're passing wether the root touch-delete accounts.
|
||||
// based on the eip phase, we're passing whether the root touch-delete accounts.
|
||||
receipt := types.NewReceipt(root, failed, *usedGas)
|
||||
receipt.TxHash = tx.Hash()
|
||||
receipt.GasUsed = gas
|
||||
|
|
|
@ -26,13 +26,13 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -525,7 +525,7 @@ func (pool *TxPool) Content() (map[common.Address]types.Transactions, map[common
|
|||
return pending, queued
|
||||
}
|
||||
|
||||
// Pending retrieves all currently processable transactions, groupped by origin
|
||||
// Pending retrieves all currently processable transactions, grouped by origin
|
||||
// account and sorted by nonce. The returned transaction set is a copy and can be
|
||||
// freely modified by calling code.
|
||||
func (pool *TxPool) Pending() (map[common.Address]types.Transactions, error) {
|
||||
|
@ -547,7 +547,7 @@ func (pool *TxPool) Locals() []common.Address {
|
|||
return pool.locals.flatten()
|
||||
}
|
||||
|
||||
// local retrieves all currently known local transactions, groupped by origin
|
||||
// local retrieves all currently known local transactions, grouped by origin
|
||||
// account and sorted by nonce. The returned transaction set is a copy and can be
|
||||
// freely modified by calling code.
|
||||
func (pool *TxPool) local() map[common.Address]types.Transactions {
|
||||
|
@ -987,11 +987,11 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
|
|||
if pending > pool.config.GlobalSlots {
|
||||
pendingBeforeCap := pending
|
||||
// Assemble a spam order to penalize large transactors first
|
||||
spammers := prque.New()
|
||||
spammers := prque.New(nil)
|
||||
for addr, list := range pool.pending {
|
||||
// Only evict transactions from high rollers
|
||||
if !pool.locals.contains(addr) && uint64(list.Len()) > pool.config.AccountSlots {
|
||||
spammers.Push(addr, float32(list.Len()))
|
||||
spammers.Push(addr, int64(list.Len()))
|
||||
}
|
||||
}
|
||||
// Gradually drop transactions from offenders
|
||||
|
|
|
@ -113,7 +113,7 @@ func LogsBloom(logs []*Log) *big.Int {
|
|||
}
|
||||
|
||||
func bloom9(b []byte) *big.Int {
|
||||
b = crypto.Keccak256(b[:])
|
||||
b = crypto.Keccak256(b)
|
||||
|
||||
r := new(big.Int)
|
||||
|
||||
|
@ -130,7 +130,7 @@ var Bloom9 = bloom9
|
|||
|
||||
func BloomLookup(bin Bloom, topic bytesBacked) bool {
|
||||
bloom := bin.Big()
|
||||
cmp := bloom9(topic.Bytes()[:])
|
||||
cmp := bloom9(topic.Bytes())
|
||||
|
||||
return bloom.And(bloom, cmp).Cmp(cmp) == 0
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ type (
|
|||
)
|
||||
|
||||
// run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
|
||||
func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
|
||||
func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, error) {
|
||||
if contract.CodeAddr != nil {
|
||||
precompiles := PrecompiledContractsHomestead
|
||||
if evm.ChainConfig().IsByzantium(evm.BlockNumber) {
|
||||
|
@ -61,7 +61,7 @@ func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
|
|||
}(evm.interpreter)
|
||||
evm.interpreter = interpreter
|
||||
}
|
||||
return interpreter.Run(contract, input)
|
||||
return interpreter.Run(contract, input, readOnly)
|
||||
}
|
||||
}
|
||||
return nil, ErrNoCompatibleInterpreter
|
||||
|
@ -136,10 +136,28 @@ func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmCon
|
|||
vmConfig: vmConfig,
|
||||
chainConfig: chainConfig,
|
||||
chainRules: chainConfig.Rules(ctx.BlockNumber),
|
||||
interpreters: make([]Interpreter, 1),
|
||||
interpreters: make([]Interpreter, 0, 1),
|
||||
}
|
||||
|
||||
evm.interpreters[0] = NewEVMInterpreter(evm, vmConfig)
|
||||
if chainConfig.IsEWASM(ctx.BlockNumber) {
|
||||
// to be implemented by EVM-C and Wagon PRs.
|
||||
// if vmConfig.EWASMInterpreter != "" {
|
||||
// extIntOpts := strings.Split(vmConfig.EWASMInterpreter, ":")
|
||||
// path := extIntOpts[0]
|
||||
// options := []string{}
|
||||
// if len(extIntOpts) > 1 {
|
||||
// options = extIntOpts[1..]
|
||||
// }
|
||||
// evm.interpreters = append(evm.interpreters, NewEVMVCInterpreter(evm, vmConfig, options))
|
||||
// } else {
|
||||
// evm.interpreters = append(evm.interpreters, NewEWASMInterpreter(evm, vmConfig))
|
||||
// }
|
||||
panic("No supported ewasm interpreter yet.")
|
||||
}
|
||||
|
||||
// vmConfig.EVMInterpreter will be used by EVM-C, it won't be checked here
|
||||
// as we always want to have the built-in EVM as the failover option.
|
||||
evm.interpreters = append(evm.interpreters, NewEVMInterpreter(evm, vmConfig))
|
||||
evm.interpreter = evm.interpreters[0]
|
||||
|
||||
return evm
|
||||
|
@ -210,7 +228,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
|||
evm.vmConfig.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
|
||||
}()
|
||||
}
|
||||
ret, err = run(evm, contract, input)
|
||||
ret, err = run(evm, contract, input, false)
|
||||
|
||||
// When an error was returned by the EVM or when setting the creation code
|
||||
// above we revert to the snapshot and consume any gas remaining. Additionally
|
||||
|
@ -255,7 +273,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
|||
contract := NewContract(caller, to, value, gas)
|
||||
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))
|
||||
|
||||
ret, err = run(evm, contract, input)
|
||||
ret, err = run(evm, contract, input, false)
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != errExecutionReverted {
|
||||
|
@ -288,7 +306,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
|||
contract := NewContract(caller, to, nil, gas).AsDelegate()
|
||||
contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr))
|
||||
|
||||
ret, err = run(evm, contract, input)
|
||||
ret, err = run(evm, contract, input, false)
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != errExecutionReverted {
|
||||
|
@ -310,13 +328,6 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
|
|||
if evm.depth > int(params.CallCreateDepth) {
|
||||
return nil, gas, ErrDepth
|
||||
}
|
||||
// Make sure the readonly is only set if we aren't in readonly yet
|
||||
// this makes also sure that the readonly flag isn't removed for
|
||||
// child calls.
|
||||
if !evm.interpreter.IsReadOnly() {
|
||||
evm.interpreter.SetReadOnly(true)
|
||||
defer func() { evm.interpreter.SetReadOnly(false) }()
|
||||
}
|
||||
|
||||
var (
|
||||
to = AccountRef(addr)
|
||||
|
@ -331,7 +342,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
|
|||
// When an error was returned by the EVM or when setting the creation code
|
||||
// above we revert to the snapshot and consume any gas remaining. Additionally
|
||||
// when we're in Homestead this also counts for code storage gas errors.
|
||||
ret, err = run(evm, contract, input)
|
||||
ret, err = run(evm, contract, input, true)
|
||||
if err != nil {
|
||||
evm.StateDB.RevertToSnapshot(snapshot)
|
||||
if err != errExecutionReverted {
|
||||
|
@ -382,7 +393,7 @@ func (evm *EVM) create(caller ContractRef, code []byte, gas uint64, value *big.I
|
|||
}
|
||||
start := time.Now()
|
||||
|
||||
ret, err := run(evm, contract, nil)
|
||||
ret, err := run(evm, contract, nil, false)
|
||||
|
||||
// check whether the max code size has been exceeded
|
||||
maxCodeSizeExceeded := evm.ChainConfig().IsEIP158(evm.BlockNumber) && len(ret) > params.MaxCodeSize
|
||||
|
|
|
@ -117,24 +117,69 @@ func gasReturnDataCopy(gt params.GasTable, evm *EVM, contract *Contract, stack *
|
|||
|
||||
func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||
var (
|
||||
y, x = stack.Back(1), stack.Back(0)
|
||||
val = evm.StateDB.GetState(contract.Address(), common.BigToHash(x))
|
||||
y, x = stack.Back(1), stack.Back(0)
|
||||
current = evm.StateDB.GetState(contract.Address(), common.BigToHash(x))
|
||||
)
|
||||
// This checks for 3 scenario's and calculates gas accordingly
|
||||
// 1. From a zero-value address to a non-zero value (NEW VALUE)
|
||||
// 2. From a non-zero value address to a zero-value address (DELETE)
|
||||
// 3. From a non-zero to a non-zero (CHANGE)
|
||||
if val == (common.Hash{}) && y.Sign() != 0 {
|
||||
// 0 => non 0
|
||||
return params.SstoreSetGas, nil
|
||||
} else if val != (common.Hash{}) && y.Sign() == 0 {
|
||||
// non 0 => 0
|
||||
evm.StateDB.AddRefund(params.SstoreRefundGas)
|
||||
return params.SstoreClearGas, nil
|
||||
} else {
|
||||
// non 0 => non 0 (or 0 => 0)
|
||||
return params.SstoreResetGas, nil
|
||||
// The legacy gas metering only takes into consideration the current state
|
||||
if !evm.chainRules.IsConstantinople {
|
||||
// This checks for 3 scenario's and calculates gas accordingly:
|
||||
//
|
||||
// 1. From a zero-value address to a non-zero value (NEW VALUE)
|
||||
// 2. From a non-zero value address to a zero-value address (DELETE)
|
||||
// 3. From a non-zero to a non-zero (CHANGE)
|
||||
switch {
|
||||
case current == (common.Hash{}) && y.Sign() != 0: // 0 => non 0
|
||||
return params.SstoreSetGas, nil
|
||||
case current != (common.Hash{}) && y.Sign() == 0: // non 0 => 0
|
||||
evm.StateDB.AddRefund(params.SstoreRefundGas)
|
||||
return params.SstoreClearGas, nil
|
||||
default: // non 0 => non 0 (or 0 => 0)
|
||||
return params.SstoreResetGas, nil
|
||||
}
|
||||
}
|
||||
// The new gas metering is based on net gas costs (EIP-1283):
|
||||
//
|
||||
// 1. If current value equals new value (this is a no-op), 200 gas is deducted.
|
||||
// 2. If current value does not equal new value
|
||||
// 2.1. If original value equals current value (this storage slot has not been changed by the current execution context)
|
||||
// 2.1.1. If original value is 0, 20000 gas is deducted.
|
||||
// 2.1.2. Otherwise, 5000 gas is deducted. If new value is 0, add 15000 gas to refund counter.
|
||||
// 2.2. If original value does not equal current value (this storage slot is dirty), 200 gas is deducted. Apply both of the following clauses.
|
||||
// 2.2.1. If original value is not 0
|
||||
// 2.2.1.1. If current value is 0 (also means that new value is not 0), remove 15000 gas from refund counter. We can prove that refund counter will never go below 0.
|
||||
// 2.2.1.2. If new value is 0 (also means that current value is not 0), add 15000 gas to refund counter.
|
||||
// 2.2.2. If original value equals new value (this storage slot is reset)
|
||||
// 2.2.2.1. If original value is 0, add 19800 gas to refund counter.
|
||||
// 2.2.2.2. Otherwise, add 4800 gas to refund counter.
|
||||
value := common.BigToHash(y)
|
||||
if current == value { // noop (1)
|
||||
return params.NetSstoreNoopGas, nil
|
||||
}
|
||||
original := evm.StateDB.GetCommittedState(contract.Address(), common.BigToHash(x))
|
||||
if original == current {
|
||||
if original == (common.Hash{}) { // create slot (2.1.1)
|
||||
return params.NetSstoreInitGas, nil
|
||||
}
|
||||
if value == (common.Hash{}) { // delete slot (2.1.2b)
|
||||
evm.StateDB.AddRefund(params.NetSstoreClearRefund)
|
||||
}
|
||||
return params.NetSstoreCleanGas, nil // write existing slot (2.1.2)
|
||||
}
|
||||
if original != (common.Hash{}) {
|
||||
if current == (common.Hash{}) { // recreate slot (2.2.1.1)
|
||||
evm.StateDB.SubRefund(params.NetSstoreClearRefund)
|
||||
} else if value == (common.Hash{}) { // delete slot (2.2.1.2)
|
||||
evm.StateDB.AddRefund(params.NetSstoreClearRefund)
|
||||
}
|
||||
}
|
||||
if original == value {
|
||||
if original == (common.Hash{}) { // reset to original inexistent slot (2.2.2.1)
|
||||
evm.StateDB.AddRefund(params.NetSstoreResetClearRefund)
|
||||
} else { // reset to original existing slot (2.2.2.2)
|
||||
evm.StateDB.AddRefund(params.NetSstoreResetRefund)
|
||||
}
|
||||
}
|
||||
return params.NetSstoreDirtyGas, nil
|
||||
}
|
||||
|
||||
func makeGasLog(n uint64) gasFunc {
|
||||
|
|
|
@ -355,7 +355,7 @@ func opSAR(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory *
|
|||
defer interpreter.intPool.put(shift) // First operand back into the pool
|
||||
|
||||
if shift.Cmp(common.Big256) >= 0 {
|
||||
if value.Sign() > 0 {
|
||||
if value.Sign() >= 0 {
|
||||
value.SetUint64(0)
|
||||
} else {
|
||||
value.SetInt64(-1)
|
||||
|
|
|
@ -40,8 +40,10 @@ type StateDB interface {
|
|||
GetCodeSize(common.Address) int
|
||||
|
||||
AddRefund(uint64)
|
||||
SubRefund(uint64)
|
||||
GetRefund() uint64
|
||||
|
||||
GetCommittedState(common.Address, common.Hash) common.Hash
|
||||
GetState(common.Address, common.Hash) common.Hash
|
||||
SetState(common.Address, common.Hash, common.Hash)
|
||||
|
||||
|
@ -64,7 +66,7 @@ type StateDB interface {
|
|||
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)
|
||||
}
|
||||
|
||||
// CallContext provides a basic interface for the EVM calling conventions. The EVM EVM
|
||||
// CallContext provides a basic interface for the EVM calling conventions. The EVM
|
||||
// depends on this context being implemented for doing subcalls and initialising new EVM contracts.
|
||||
type CallContext interface {
|
||||
// Call another contract
|
||||
|
|
|
@ -39,6 +39,11 @@ type Config struct {
|
|||
// may be left uninitialised and will be set to the default
|
||||
// table.
|
||||
JumpTable [256]operation
|
||||
|
||||
// Type of the EWASM interpreter
|
||||
EWASMInterpreter string
|
||||
// Type of the EVM interpreter
|
||||
EVMInterpreter string
|
||||
}
|
||||
|
||||
// Interpreter is used to run Ethereum based contracts and will utilise the
|
||||
|
@ -48,7 +53,7 @@ type Config struct {
|
|||
type Interpreter interface {
|
||||
// Run loops and evaluates the contract's code with the given input data and returns
|
||||
// the return byte-slice and an error if one occurred.
|
||||
Run(contract *Contract, input []byte) ([]byte, error)
|
||||
Run(contract *Contract, input []byte, static bool) ([]byte, error)
|
||||
// CanRun tells if the contract, passed as an argument, can be
|
||||
// run by the current interpreter. This is meant so that the
|
||||
// caller can do something like:
|
||||
|
@ -61,10 +66,6 @@ type Interpreter interface {
|
|||
// }
|
||||
// ```
|
||||
CanRun([]byte) bool
|
||||
// IsReadOnly reports if the interpreter is in read only mode.
|
||||
IsReadOnly() bool
|
||||
// SetReadOnly sets (or unsets) read only mode in the interpreter.
|
||||
SetReadOnly(bool)
|
||||
}
|
||||
|
||||
// EVMInterpreter represents an EVM interpreter
|
||||
|
@ -125,7 +126,7 @@ func (in *EVMInterpreter) enforceRestrictions(op OpCode, operation operation, st
|
|||
// It's important to note that any errors returned by the interpreter should be
|
||||
// considered a revert-and-consume-all-gas operation except for
|
||||
// errExecutionReverted which means revert-and-keep-gas-left.
|
||||
func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err error) {
|
||||
func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
|
||||
if in.intPool == nil {
|
||||
in.intPool = poolOfIntPools.get()
|
||||
defer func() {
|
||||
|
@ -138,6 +139,13 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err
|
|||
in.evm.depth++
|
||||
defer func() { in.evm.depth-- }()
|
||||
|
||||
// Make sure the readOnly is only set if we aren't in readOnly yet.
|
||||
// This makes also sure that the readOnly flag isn't removed for child calls.
|
||||
if readOnly && !in.readOnly {
|
||||
in.readOnly = true
|
||||
defer func() { in.readOnly = false }()
|
||||
}
|
||||
|
||||
// Reset the previous call's return data. It's unimportant to preserve the old buffer
|
||||
// as every returning call will return new data anyway.
|
||||
in.returnData = nil
|
||||
|
@ -263,13 +271,3 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte) (ret []byte, err
|
|||
func (in *EVMInterpreter) CanRun(code []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsReadOnly reports if the interpreter is in read only mode.
|
||||
func (in *EVMInterpreter) IsReadOnly() bool {
|
||||
return in.readOnly
|
||||
}
|
||||
|
||||
// SetReadOnly sets (or unsets) read only mode in the interpreter.
|
||||
func (in *EVMInterpreter) SetReadOnly(ro bool) {
|
||||
in.readOnly = ro
|
||||
}
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
// Copyright 2016 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package vm
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
)
|
||||
|
||||
func NoopCanTransfer(db StateDB, from common.Address, balance *big.Int) bool {
|
||||
return true
|
||||
}
|
||||
func NoopTransfer(db StateDB, from, to common.Address, amount *big.Int) {}
|
||||
|
||||
type NoopEVMCallContext struct{}
|
||||
|
||||
func (NoopEVMCallContext) Call(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (NoopEVMCallContext) CallCode(caller ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
func (NoopEVMCallContext) Create(caller ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error) {
|
||||
return nil, common.Address{}, nil
|
||||
}
|
||||
func (NoopEVMCallContext) DelegateCall(me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type NoopStateDB struct{}
|
||||
|
||||
func (NoopStateDB) CreateAccount(common.Address) {}
|
||||
func (NoopStateDB) SubBalance(common.Address, *big.Int) {}
|
||||
func (NoopStateDB) AddBalance(common.Address, *big.Int) {}
|
||||
func (NoopStateDB) GetBalance(common.Address) *big.Int { return nil }
|
||||
func (NoopStateDB) GetNonce(common.Address) uint64 { return 0 }
|
||||
func (NoopStateDB) SetNonce(common.Address, uint64) {}
|
||||
func (NoopStateDB) GetCodeHash(common.Address) common.Hash { return common.Hash{} }
|
||||
func (NoopStateDB) GetCode(common.Address) []byte { return nil }
|
||||
func (NoopStateDB) SetCode(common.Address, []byte) {}
|
||||
func (NoopStateDB) GetCodeSize(common.Address) int { return 0 }
|
||||
func (NoopStateDB) AddRefund(uint64) {}
|
||||
func (NoopStateDB) GetRefund() uint64 { return 0 }
|
||||
func (NoopStateDB) GetState(common.Address, common.Hash) common.Hash { return common.Hash{} }
|
||||
func (NoopStateDB) SetState(common.Address, common.Hash, common.Hash) {}
|
||||
func (NoopStateDB) Suicide(common.Address) bool { return false }
|
||||
func (NoopStateDB) HasSuicided(common.Address) bool { return false }
|
||||
func (NoopStateDB) Exist(common.Address) bool { return false }
|
||||
func (NoopStateDB) Empty(common.Address) bool { return false }
|
||||
func (NoopStateDB) RevertToSnapshot(int) {}
|
||||
func (NoopStateDB) Snapshot() int { return 0 }
|
||||
func (NoopStateDB) AddLog(*types.Log) {}
|
||||
func (NoopStateDB) AddPreimage(common.Hash, []byte) {}
|
||||
func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {}
|
2
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/secp256k1.c
generated
vendored
2
vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1/src/secp256k1.c
generated
vendored
|
@ -26,7 +26,6 @@
|
|||
} while(0)
|
||||
|
||||
static void default_illegal_callback_fn(const char* str, void* data) {
|
||||
(void)data;
|
||||
fprintf(stderr, "[libsecp256k1] illegal argument: %s\n", str);
|
||||
abort();
|
||||
}
|
||||
|
@ -37,7 +36,6 @@ static const secp256k1_callback default_illegal_callback = {
|
|||
};
|
||||
|
||||
static void default_error_callback_fn(const char* str, void* data) {
|
||||
(void)data;
|
||||
fprintf(stderr, "[libsecp256k1] internal consistency check failed: %s\n", str);
|
||||
abort();
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block
|
|||
|
||||
// traceChain configures a new tracer according to the provided configuration, and
|
||||
// executes all the transactions contained within. The return value will be one item
|
||||
// per transaction, dependent on the requestd tracer.
|
||||
// per transaction, dependent on the requested tracer.
|
||||
func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Block, config *TraceConfig) (*rpc.Subscription, error) {
|
||||
// Tracing a chain is a **long** operation, only do with subscriptions
|
||||
notifier, supported := rpc.NotifierFromContext(ctx)
|
||||
|
|
|
@ -149,10 +149,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
rawdb.WriteDatabaseVersion(chainDb, core.BlockChainVersion)
|
||||
}
|
||||
var (
|
||||
vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording}
|
||||
vmConfig = vm.Config{
|
||||
EnablePreimageRecording: config.EnablePreimageRecording,
|
||||
EWASMInterpreter: config.EWASMInterpreter,
|
||||
EVMInterpreter: config.EVMInterpreter,
|
||||
}
|
||||
cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieNodeLimit: config.TrieCache, TrieTimeLimit: config.TrieTimeout}
|
||||
)
|
||||
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig)
|
||||
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, eth.chainConfig, eth.engine, vmConfig, eth.shouldPreserve)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -173,7 +177,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil)
|
||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock)
|
||||
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
|
||||
|
||||
eth.APIBackend = &EthAPIBackend{eth, nil}
|
||||
|
@ -330,6 +334,60 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
|
|||
return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
|
||||
}
|
||||
|
||||
// isLocalBlock checks whether the specified block is mined
|
||||
// by local miner accounts.
|
||||
//
|
||||
// We regard two types of accounts as local miner account: etherbase
|
||||
// and accounts specified via `txpool.locals` flag.
|
||||
func (s *Ethereum) isLocalBlock(block *types.Block) bool {
|
||||
author, err := s.engine.Author(block.Header())
|
||||
if err != nil {
|
||||
log.Warn("Failed to retrieve block author", "number", block.NumberU64(), "hash", block.Hash(), "err", err)
|
||||
return false
|
||||
}
|
||||
// Check whether the given address is etherbase.
|
||||
s.lock.RLock()
|
||||
etherbase := s.etherbase
|
||||
s.lock.RUnlock()
|
||||
if author == etherbase {
|
||||
return true
|
||||
}
|
||||
// Check whether the given address is specified by `txpool.local`
|
||||
// CLI flag.
|
||||
for _, account := range s.config.TxPool.Locals {
|
||||
if account == author {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// shouldPreserve checks whether we should preserve the given block
|
||||
// during the chain reorg depending on whether the author of block
|
||||
// is a local account.
|
||||
func (s *Ethereum) shouldPreserve(block *types.Block) bool {
|
||||
// The reason we need to disable the self-reorg preserving for clique
|
||||
// is it can be probable to introduce a deadlock.
|
||||
//
|
||||
// e.g. If there are 7 available signers
|
||||
//
|
||||
// r1 A
|
||||
// r2 B
|
||||
// r3 C
|
||||
// r4 D
|
||||
// r5 A [X] F G
|
||||
// r6 [X]
|
||||
//
|
||||
// In the round5, the inturn signer E is offline, so the worst case
|
||||
// is A, F and G sign the block of round5 and reject the block of opponents
|
||||
// and in the round6, the last available signer B is offline, the whole
|
||||
// network is stuck.
|
||||
if _, ok := s.engine.(*clique.Clique); ok {
|
||||
return false
|
||||
}
|
||||
return s.isLocalBlock(block)
|
||||
}
|
||||
|
||||
// SetEtherbase sets the mining reward address.
|
||||
func (s *Ethereum) SetEtherbase(etherbase common.Address) {
|
||||
s.lock.Lock()
|
||||
|
@ -362,7 +420,7 @@ func (s *Ethereum) StartMining(threads int) error {
|
|||
s.lock.RUnlock()
|
||||
s.txPool.SetGasPrice(price)
|
||||
|
||||
// Configure the local mining addess
|
||||
// Configure the local mining address
|
||||
eb, err := s.Etherbase()
|
||||
if err != nil {
|
||||
log.Error("Cannot start mining without etherbase", "err", err)
|
||||
|
|
|
@ -121,6 +121,11 @@ type Config struct {
|
|||
|
||||
// Miscellaneous options
|
||||
DocRoot string `toml:"-"`
|
||||
|
||||
// Type of the EWASM interpreter ("" for detault)
|
||||
EWASMInterpreter string
|
||||
// Type of the EVM interpreter ("" for default)
|
||||
EVMInterpreter string
|
||||
}
|
||||
|
||||
type configMarshaling struct {
|
||||
|
|
|
@ -40,8 +40,8 @@ type PublicDownloaderAPI struct {
|
|||
// installSyncSubscription channel.
|
||||
func NewPublicDownloaderAPI(d *Downloader, m *event.TypeMux) *PublicDownloaderAPI {
|
||||
api := &PublicDownloaderAPI{
|
||||
d: d,
|
||||
mux: m,
|
||||
d: d,
|
||||
mux: m,
|
||||
installSyncSubscription: make(chan chan interface{}),
|
||||
uninstallSyncSubscription: make(chan *uninstallSyncSubscriptionRequest),
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -105,11 +105,11 @@ func newQueue() *queue {
|
|||
headerPendPool: make(map[string]*fetchRequest),
|
||||
headerContCh: make(chan bool),
|
||||
blockTaskPool: make(map[common.Hash]*types.Header),
|
||||
blockTaskQueue: prque.New(),
|
||||
blockTaskQueue: prque.New(nil),
|
||||
blockPendPool: make(map[string]*fetchRequest),
|
||||
blockDonePool: make(map[common.Hash]struct{}),
|
||||
receiptTaskPool: make(map[common.Hash]*types.Header),
|
||||
receiptTaskQueue: prque.New(),
|
||||
receiptTaskQueue: prque.New(nil),
|
||||
receiptPendPool: make(map[string]*fetchRequest),
|
||||
receiptDonePool: make(map[common.Hash]struct{}),
|
||||
resultCache: make([]*fetchResult, blockCacheItems),
|
||||
|
@ -277,7 +277,7 @@ func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) {
|
|||
}
|
||||
// Schedule all the header retrieval tasks for the skeleton assembly
|
||||
q.headerTaskPool = make(map[uint64]*types.Header)
|
||||
q.headerTaskQueue = prque.New()
|
||||
q.headerTaskQueue = prque.New(nil)
|
||||
q.headerPeerMiss = make(map[string]map[uint64]struct{}) // Reset availability to correct invalid chains
|
||||
q.headerResults = make([]*types.Header, len(skeleton)*MaxHeaderFetch)
|
||||
q.headerProced = 0
|
||||
|
@ -288,7 +288,7 @@ func (q *queue) ScheduleSkeleton(from uint64, skeleton []*types.Header) {
|
|||
index := from + uint64(i*MaxHeaderFetch)
|
||||
|
||||
q.headerTaskPool[index] = header
|
||||
q.headerTaskQueue.Push(index, -float32(index))
|
||||
q.headerTaskQueue.Push(index, -int64(index))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,11 +334,11 @@ func (q *queue) Schedule(headers []*types.Header, from uint64) []*types.Header {
|
|||
}
|
||||
// Queue the header for content retrieval
|
||||
q.blockTaskPool[hash] = header
|
||||
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
|
||||
if q.mode == FastSync {
|
||||
q.receiptTaskPool[hash] = header
|
||||
q.receiptTaskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
inserts = append(inserts, header)
|
||||
q.headerHead = hash
|
||||
|
@ -436,7 +436,7 @@ func (q *queue) ReserveHeaders(p *peerConnection, count int) *fetchRequest {
|
|||
}
|
||||
// Merge all the skipped batches back
|
||||
for _, from := range skip {
|
||||
q.headerTaskQueue.Push(from, -float32(from))
|
||||
q.headerTaskQueue.Push(from, -int64(from))
|
||||
}
|
||||
// Assemble and return the block download request
|
||||
if send == 0 {
|
||||
|
@ -542,7 +542,7 @@ func (q *queue) reserveHeaders(p *peerConnection, count int, taskPool map[common
|
|||
}
|
||||
// Merge all the skipped headers back
|
||||
for _, header := range skip {
|
||||
taskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
if progress {
|
||||
// Wake WaitResults, resultCache was modified
|
||||
|
@ -585,10 +585,10 @@ func (q *queue) cancel(request *fetchRequest, taskQueue *prque.Prque, pendPool m
|
|||
defer q.lock.Unlock()
|
||||
|
||||
if request.From > 0 {
|
||||
taskQueue.Push(request.From, -float32(request.From))
|
||||
taskQueue.Push(request.From, -int64(request.From))
|
||||
}
|
||||
for _, header := range request.Headers {
|
||||
taskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
delete(pendPool, request.Peer.id)
|
||||
}
|
||||
|
@ -602,13 +602,13 @@ func (q *queue) Revoke(peerID string) {
|
|||
|
||||
if request, ok := q.blockPendPool[peerID]; ok {
|
||||
for _, header := range request.Headers {
|
||||
q.blockTaskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
q.blockTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
delete(q.blockPendPool, peerID)
|
||||
}
|
||||
if request, ok := q.receiptPendPool[peerID]; ok {
|
||||
for _, header := range request.Headers {
|
||||
q.receiptTaskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
q.receiptTaskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
delete(q.receiptPendPool, peerID)
|
||||
}
|
||||
|
@ -657,10 +657,10 @@ func (q *queue) expire(timeout time.Duration, pendPool map[string]*fetchRequest,
|
|||
|
||||
// Return any non satisfied requests to the pool
|
||||
if request.From > 0 {
|
||||
taskQueue.Push(request.From, -float32(request.From))
|
||||
taskQueue.Push(request.From, -int64(request.From))
|
||||
}
|
||||
for _, header := range request.Headers {
|
||||
taskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
// Add the peer to the expiry report along the number of failed requests
|
||||
expiries[id] = len(request.Headers)
|
||||
|
@ -731,7 +731,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, headerProcCh
|
|||
}
|
||||
miss[request.From] = struct{}{}
|
||||
|
||||
q.headerTaskQueue.Push(request.From, -float32(request.From))
|
||||
q.headerTaskQueue.Push(request.From, -int64(request.From))
|
||||
return 0, errors.New("delivery not accepted")
|
||||
}
|
||||
// Clean up a successful fetch and try to deliver any sub-results
|
||||
|
@ -854,7 +854,7 @@ func (q *queue) deliver(id string, taskPool map[common.Hash]*types.Header, taskQ
|
|||
// Return all failed or missing fetches to the queue
|
||||
for _, header := range request.Headers {
|
||||
if header != nil {
|
||||
taskQueue.Push(header, -float32(header.Number.Uint64()))
|
||||
taskQueue.Push(header, -int64(header.Number.Uint64()))
|
||||
}
|
||||
}
|
||||
// Wake up WaitResults
|
||||
|
|
|
@ -23,10 +23,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/prque"
|
||||
"github.com/ethereum/go-ethereum/consensus"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -160,7 +160,7 @@ func New(getBlock blockRetrievalFn, verifyHeader headerVerifierFn, broadcastBloc
|
|||
fetching: make(map[common.Hash]*announce),
|
||||
fetched: make(map[common.Hash][]*announce),
|
||||
completing: make(map[common.Hash]*announce),
|
||||
queue: prque.New(),
|
||||
queue: prque.New(nil),
|
||||
queues: make(map[string]int),
|
||||
queued: make(map[common.Hash]*inject),
|
||||
getBlock: getBlock,
|
||||
|
@ -299,7 +299,7 @@ func (f *Fetcher) loop() {
|
|||
// If too high up the chain or phase, continue later
|
||||
number := op.block.NumberU64()
|
||||
if number > height+1 {
|
||||
f.queue.Push(op, -float32(number))
|
||||
f.queue.Push(op, -int64(number))
|
||||
if f.queueChangeHook != nil {
|
||||
f.queueChangeHook(hash, true)
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ func (f *Fetcher) enqueue(peer string, block *types.Block) {
|
|||
}
|
||||
f.queues[peer] = count
|
||||
f.queued[hash] = op
|
||||
f.queue.Push(op, -float32(block.NumberU64()))
|
||||
f.queue.Push(op, -int64(block.NumberU64()))
|
||||
if f.queueChangeHook != nil {
|
||||
f.queueChangeHook(op.block.Hash(), true)
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func (mw *memoryWrapper) pushObject(vm *duktape.Context) {
|
|||
ctx.Pop2()
|
||||
|
||||
ptr := ctx.PushFixedBuffer(len(blob))
|
||||
copy(makeSlice(ptr, uint(len(blob))), blob[:])
|
||||
copy(makeSlice(ptr, uint(len(blob))), blob)
|
||||
return 1
|
||||
})
|
||||
vm.PutPropString(obj, "slice")
|
||||
|
@ -204,7 +204,7 @@ func (dw *dbWrapper) pushObject(vm *duktape.Context) {
|
|||
code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx)))
|
||||
|
||||
ptr := ctx.PushFixedBuffer(len(code))
|
||||
copy(makeSlice(ptr, uint(len(code))), code[:])
|
||||
copy(makeSlice(ptr, uint(len(code))), code)
|
||||
return 1
|
||||
})
|
||||
vm.PutPropString(obj, "getCode")
|
||||
|
@ -268,7 +268,7 @@ func (cw *contractWrapper) pushObject(vm *duktape.Context) {
|
|||
blob := cw.contract.Input
|
||||
|
||||
ptr := ctx.PushFixedBuffer(len(blob))
|
||||
copy(makeSlice(ptr, uint(len(blob))), blob[:])
|
||||
copy(makeSlice(ptr, uint(len(blob))), blob)
|
||||
return 1
|
||||
})
|
||||
vm.PutPropString(obj, "getInput")
|
||||
|
@ -584,7 +584,7 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) {
|
|||
|
||||
case []byte:
|
||||
ptr := jst.vm.PushFixedBuffer(len(val))
|
||||
copy(makeSlice(ptr, uint(len(val))), val[:])
|
||||
copy(makeSlice(ptr, uint(len(val))), val)
|
||||
|
||||
case common.Address:
|
||||
ptr := jst.vm.PushFixedBuffer(20)
|
||||
|
|
|
@ -155,15 +155,12 @@ func (db *LDBDatabase) LDB() *leveldb.DB {
|
|||
|
||||
// Meter configures the database metrics collectors and
|
||||
func (db *LDBDatabase) Meter(prefix string) {
|
||||
if metrics.Enabled {
|
||||
// Initialize all the metrics collector at the requested prefix
|
||||
db.compTimeMeter = metrics.NewRegisteredMeter(prefix+"compact/time", nil)
|
||||
db.compReadMeter = metrics.NewRegisteredMeter(prefix+"compact/input", nil)
|
||||
db.compWriteMeter = metrics.NewRegisteredMeter(prefix+"compact/output", nil)
|
||||
db.diskReadMeter = metrics.NewRegisteredMeter(prefix+"disk/read", nil)
|
||||
db.diskWriteMeter = metrics.NewRegisteredMeter(prefix+"disk/write", nil)
|
||||
}
|
||||
// Initialize write delay metrics no matter we are in metric mode or not.
|
||||
// Initialize all the metrics collector at the requested prefix
|
||||
db.compTimeMeter = metrics.NewRegisteredMeter(prefix+"compact/time", nil)
|
||||
db.compReadMeter = metrics.NewRegisteredMeter(prefix+"compact/input", nil)
|
||||
db.compWriteMeter = metrics.NewRegisteredMeter(prefix+"compact/output", nil)
|
||||
db.diskReadMeter = metrics.NewRegisteredMeter(prefix+"disk/read", nil)
|
||||
db.diskWriteMeter = metrics.NewRegisteredMeter(prefix+"disk/write", nil)
|
||||
db.writeDelayMeter = metrics.NewRegisteredMeter(prefix+"compact/writedelay/duration", nil)
|
||||
db.writeDelayNMeter = metrics.NewRegisteredMeter(prefix+"compact/writedelay/counter", nil)
|
||||
|
||||
|
|
|
@ -143,9 +143,9 @@ func CopyFile(dst, src string, mode os.FileMode) {
|
|||
// so that go commands executed by build use the same version of Go as the 'host' that runs
|
||||
// build code. e.g.
|
||||
//
|
||||
// /usr/lib/go-1.8/bin/go run build/ci.go ...
|
||||
// /usr/lib/go-1.11/bin/go run build/ci.go ...
|
||||
//
|
||||
// runs using go 1.8 and invokes go 1.8 tools from the same GOROOT. This is also important
|
||||
// runs using go 1.11 and invokes go 1.11 tools from the same GOROOT. This is also important
|
||||
// because runtime.Version checks on the host should match the tools that are run.
|
||||
func GoTool(tool string, args ...string) *exec.Cmd {
|
||||
args = append([]string{tool}, args...)
|
||||
|
|
|
@ -42,12 +42,12 @@ type lesCommons struct {
|
|||
// NodeInfo represents a short summary of the Ethereum sub-protocol metadata
|
||||
// known about the host peer.
|
||||
type NodeInfo struct {
|
||||
Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
|
||||
Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain
|
||||
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block
|
||||
Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules
|
||||
Head common.Hash `json:"head"` // SHA3 hash of the host's best owned block
|
||||
CHT light.TrustedCheckpoint `json:"cht"` // Trused CHT checkpoint for fast catchup
|
||||
Network uint64 `json:"network"` // Ethereum network ID (1=Frontier, 2=Morden, Ropsten=3, Rinkeby=4)
|
||||
Difficulty *big.Int `json:"difficulty"` // Total difficulty of the host's blockchain
|
||||
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block
|
||||
Config *params.ChainConfig `json:"config"` // Chain configuration for the fork rules
|
||||
Head common.Hash `json:"head"` // SHA3 hash of the host's best owned block
|
||||
CHT params.TrustedCheckpoint `json:"cht"` // Trused CHT checkpoint for fast catchup
|
||||
}
|
||||
|
||||
// makeProtocols creates protocol descriptors for the given LES versions.
|
||||
|
@ -76,7 +76,7 @@ func (c *lesCommons) makeProtocols(versions []uint) []p2p.Protocol {
|
|||
|
||||
// nodeInfo retrieves some protocol metadata about the running host node.
|
||||
func (c *lesCommons) nodeInfo() interface{} {
|
||||
var cht light.TrustedCheckpoint
|
||||
var cht params.TrustedCheckpoint
|
||||
sections, _, _ := c.chtIndexer.Sections()
|
||||
sections2, _, _ := c.bloomTrieIndexer.Sections()
|
||||
|
||||
|
@ -98,11 +98,11 @@ func (c *lesCommons) nodeInfo() interface{} {
|
|||
idxV2 := (sectionIndex+1)*c.iConfig.PairChtSize/c.iConfig.ChtSize - 1
|
||||
chtRoot = light.GetChtRoot(c.chainDb, idxV2, sectionHead)
|
||||
}
|
||||
cht = light.TrustedCheckpoint{
|
||||
SectionIdx: sectionIndex,
|
||||
SectionHead: sectionHead,
|
||||
CHTRoot: chtRoot,
|
||||
BloomRoot: light.GetBloomTrieRoot(c.chainDb, sectionIndex, sectionHead),
|
||||
cht = params.TrustedCheckpoint{
|
||||
SectionIndex: sectionIndex,
|
||||
SectionHead: sectionHead,
|
||||
CHTRoot: chtRoot,
|
||||
BloomRoot: light.GetBloomTrieRoot(c.chainDb, sectionIndex, sectionHead),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,9 @@ func (d *requestDistributor) loop() {
|
|||
d.lock.Lock()
|
||||
elem := d.reqQueue.Front()
|
||||
for elem != nil {
|
||||
close(elem.Value.(*distReq).sentChn)
|
||||
req := elem.Value.(*distReq)
|
||||
close(req.sentChn)
|
||||
req.sentChn = nil
|
||||
elem = elem.Next()
|
||||
}
|
||||
d.lock.Unlock()
|
||||
|
|
|
@ -478,7 +478,7 @@ func (r *ChtRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
}
|
||||
|
||||
type BloomReq struct {
|
||||
BloomTrieNum, BitIdx, SectionIdx, FromLevel uint64
|
||||
BloomTrieNum, BitIdx, SectionIndex, FromLevel uint64
|
||||
}
|
||||
|
||||
// ODR request type for requesting headers by Canonical Hash Trie, see LesOdrRequest interface
|
||||
|
@ -487,7 +487,7 @@ type BloomRequest light.BloomRequest
|
|||
// GetCost returns the cost of the given ODR request according to the serving
|
||||
// peer's cost table (implementation of LesOdrRequest)
|
||||
func (r *BloomRequest) GetCost(peer *peer) uint64 {
|
||||
return peer.GetRequestCost(GetHelperTrieProofsMsg, len(r.SectionIdxList))
|
||||
return peer.GetRequestCost(GetHelperTrieProofsMsg, len(r.SectionIndexList))
|
||||
}
|
||||
|
||||
// CanSend tells if a certain peer is suitable for serving the given request
|
||||
|
@ -503,13 +503,13 @@ func (r *BloomRequest) CanSend(peer *peer) bool {
|
|||
|
||||
// Request sends an ODR request to the LES network (implementation of LesOdrRequest)
|
||||
func (r *BloomRequest) Request(reqID uint64, peer *peer) error {
|
||||
peer.Log().Debug("Requesting BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIdxList)
|
||||
reqs := make([]HelperTrieReq, len(r.SectionIdxList))
|
||||
peer.Log().Debug("Requesting BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList)
|
||||
reqs := make([]HelperTrieReq, len(r.SectionIndexList))
|
||||
|
||||
var encNumber [10]byte
|
||||
binary.BigEndian.PutUint16(encNumber[:2], uint16(r.BitIdx))
|
||||
|
||||
for i, sectionIdx := range r.SectionIdxList {
|
||||
for i, sectionIdx := range r.SectionIndexList {
|
||||
binary.BigEndian.PutUint64(encNumber[2:], sectionIdx)
|
||||
reqs[i] = HelperTrieReq{
|
||||
Type: htBloomBits,
|
||||
|
@ -524,7 +524,7 @@ func (r *BloomRequest) Request(reqID uint64, peer *peer) error {
|
|||
// returns true and stores results in memory if the message was a valid reply
|
||||
// to the request (implementation of LesOdrRequest)
|
||||
func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
|
||||
log.Debug("Validating BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIdxList)
|
||||
log.Debug("Validating BloomBits", "bloomTrie", r.BloomTrieNum, "bitIdx", r.BitIdx, "sections", r.SectionIndexList)
|
||||
|
||||
// Ensure we have a correct message with a single proof element
|
||||
if msg.MsgType != MsgHelperTrieProofs {
|
||||
|
@ -535,13 +535,13 @@ func (r *BloomRequest) Validate(db ethdb.Database, msg *Msg) error {
|
|||
nodeSet := proofs.NodeSet()
|
||||
reads := &readTraceDB{db: nodeSet}
|
||||
|
||||
r.BloomBits = make([][]byte, len(r.SectionIdxList))
|
||||
r.BloomBits = make([][]byte, len(r.SectionIndexList))
|
||||
|
||||
// Verify the proofs
|
||||
var encNumber [10]byte
|
||||
binary.BigEndian.PutUint16(encNumber[:2], uint16(r.BitIdx))
|
||||
|
||||
for i, idx := range r.SectionIdxList {
|
||||
for i, idx := range r.SectionIndexList {
|
||||
binary.BigEndian.PutUint64(encNumber[2:], idx)
|
||||
value, _, err := trie.VerifyProof(r.BloomTrieRoot, encNumber[:], reads)
|
||||
if err != nil {
|
||||
|
|
|
@ -217,6 +217,13 @@ func (r *sentReq) stateRequesting() reqStateFn {
|
|||
go r.tryRequest()
|
||||
r.lastReqQueued = true
|
||||
return r.stateRequesting
|
||||
case rpDeliveredInvalid:
|
||||
// if it was the last sent request (set to nil by update) then start a new one
|
||||
if !r.lastReqQueued && r.lastReqSentTo == nil {
|
||||
go r.tryRequest()
|
||||
r.lastReqQueued = true
|
||||
}
|
||||
return r.stateRequesting
|
||||
case rpDeliveredValid:
|
||||
r.stop(nil)
|
||||
return r.stateStopped
|
||||
|
@ -242,7 +249,11 @@ func (r *sentReq) stateNoMorePeers() reqStateFn {
|
|||
r.stop(nil)
|
||||
return r.stateStopped
|
||||
}
|
||||
return r.stateNoMorePeers
|
||||
if r.waiting() {
|
||||
return r.stateNoMorePeers
|
||||
}
|
||||
r.stop(light.ErrNoPeers)
|
||||
return nil
|
||||
case <-r.stopCh:
|
||||
return r.stateStopped
|
||||
}
|
||||
|
|
|
@ -118,19 +118,19 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
|
|||
}
|
||||
|
||||
// addTrustedCheckpoint adds a trusted checkpoint to the blockchain
|
||||
func (self *LightChain) addTrustedCheckpoint(cp TrustedCheckpoint) {
|
||||
func (self *LightChain) addTrustedCheckpoint(cp *params.TrustedCheckpoint) {
|
||||
if self.odr.ChtIndexer() != nil {
|
||||
StoreChtRoot(self.chainDb, cp.SectionIdx, cp.SectionHead, cp.CHTRoot)
|
||||
self.odr.ChtIndexer().AddCheckpoint(cp.SectionIdx, cp.SectionHead)
|
||||
StoreChtRoot(self.chainDb, cp.SectionIndex, cp.SectionHead, cp.CHTRoot)
|
||||
self.odr.ChtIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
if self.odr.BloomTrieIndexer() != nil {
|
||||
StoreBloomTrieRoot(self.chainDb, cp.SectionIdx, cp.SectionHead, cp.BloomRoot)
|
||||
self.odr.BloomTrieIndexer().AddCheckpoint(cp.SectionIdx, cp.SectionHead)
|
||||
StoreBloomTrieRoot(self.chainDb, cp.SectionIndex, cp.SectionHead, cp.BloomRoot)
|
||||
self.odr.BloomTrieIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
if self.odr.BloomIndexer() != nil {
|
||||
self.odr.BloomIndexer().AddCheckpoint(cp.SectionIdx, cp.SectionHead)
|
||||
self.odr.BloomIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
log.Info("Added trusted checkpoint", "chain", cp.name, "block", (cp.SectionIdx+1)*self.indexerConfig.ChtSize-1, "hash", cp.SectionHead)
|
||||
log.Info("Added trusted checkpoint", "chain", cp.Name, "block", (cp.SectionIndex+1)*self.indexerConfig.ChtSize-1, "hash", cp.SectionHead)
|
||||
}
|
||||
|
||||
func (self *LightChain) getProcInterrupt() bool {
|
||||
|
@ -157,7 +157,7 @@ func (self *LightChain) loadLastState() error {
|
|||
// Issue a status log and return
|
||||
header := self.hc.CurrentHeader()
|
||||
headerTd := self.GetTd(header.Hash(), header.Number.Uint64())
|
||||
log.Info("Loaded most recent local header", "number", header.Number, "hash", header.Hash(), "td", headerTd)
|
||||
log.Info("Loaded most recent local header", "number", header.Number, "hash", header.Hash(), "td", headerTd, "age", common.PrettyAge(time.Unix(header.Time.Int64(), 0)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -488,7 +488,7 @@ func (self *LightChain) SyncCht(ctx context.Context) bool {
|
|||
|
||||
// Ensure the chain didn't move past the latest block while retrieving it
|
||||
if self.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
||||
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash())
|
||||
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash(), "age", common.PrettyAge(time.Unix(header.Time.Int64(), 0)))
|
||||
self.hc.SetCurrentHeader(header)
|
||||
}
|
||||
return true
|
||||
|
|
|
@ -157,18 +157,18 @@ func (req *ChtRequest) StoreResult(db ethdb.Database) {
|
|||
// BloomRequest is the ODR request type for retrieving bloom filters from a CHT structure
|
||||
type BloomRequest struct {
|
||||
OdrRequest
|
||||
Config *IndexerConfig
|
||||
BloomTrieNum uint64
|
||||
BitIdx uint
|
||||
SectionIdxList []uint64
|
||||
BloomTrieRoot common.Hash
|
||||
BloomBits [][]byte
|
||||
Proofs *NodeSet
|
||||
Config *IndexerConfig
|
||||
BloomTrieNum uint64
|
||||
BitIdx uint
|
||||
SectionIndexList []uint64
|
||||
BloomTrieRoot common.Hash
|
||||
BloomBits [][]byte
|
||||
Proofs *NodeSet
|
||||
}
|
||||
|
||||
// StoreResult stores the retrieved data in local database
|
||||
func (req *BloomRequest) StoreResult(db ethdb.Database) {
|
||||
for i, sectionIdx := range req.SectionIdxList {
|
||||
for i, sectionIdx := range req.SectionIndexList {
|
||||
sectionHead := rawdb.ReadCanonicalHash(db, (sectionIdx+1)*req.Config.BloomTrieSize-1)
|
||||
// if we don't have the canonical hash stored for this section head number, we'll still store it under
|
||||
// a key with a zero sectionHead. GetBloomBits will look there too if we still don't have the canonical
|
||||
|
|
|
@ -222,7 +222,7 @@ func GetBloomBits(ctx context.Context, odr OdrBackend, bitIdx uint, sectionIdxLi
|
|||
}
|
||||
|
||||
r := &BloomRequest{BloomTrieRoot: GetBloomTrieRoot(db, bloomTrieCount-1, sectionHead), BloomTrieNum: bloomTrieCount - 1,
|
||||
BitIdx: bitIdx, SectionIdxList: reqList, Config: odr.IndexerConfig()}
|
||||
BitIdx: bitIdx, SectionIndexList: reqList, Config: odr.IndexerConfig()}
|
||||
if err := odr.Retrieve(ctx, r); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
|
|
|
@ -104,38 +104,11 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
// trustedCheckpoint represents a set of post-processed trie roots (CHT and BloomTrie) associated with
|
||||
// the appropriate section index and head hash. It is used to start light syncing from this checkpoint
|
||||
// and avoid downloading the entire header chain while still being able to securely access old headers/logs.
|
||||
type TrustedCheckpoint struct {
|
||||
name string
|
||||
SectionIdx uint64
|
||||
SectionHead, CHTRoot, BloomRoot common.Hash
|
||||
}
|
||||
|
||||
// trustedCheckpoints associates each known checkpoint with the genesis hash of the chain it belongs to
|
||||
var trustedCheckpoints = map[common.Hash]TrustedCheckpoint{
|
||||
params.MainnetGenesisHash: {
|
||||
name: "mainnet",
|
||||
SectionIdx: 187,
|
||||
SectionHead: common.HexToHash("e6baa034efa31562d71ff23676512dec6562c1ad0301e08843b907e81958c696"),
|
||||
CHTRoot: common.HexToHash("28001955219719cf06de1b08648969139d123a9835fc760547a1e4dabdabc15a"),
|
||||
BloomRoot: common.HexToHash("395ca2373fc662720ac6b58b3bbe71f68aa0f38b63b2d3553dd32ff3c51eebc4"),
|
||||
},
|
||||
params.TestnetGenesisHash: {
|
||||
name: "ropsten",
|
||||
SectionIdx: 117,
|
||||
SectionHead: common.HexToHash("9529b38631ae30783f56cbe4c3b9f07575b770ecba4f6e20a274b1e2f40fede1"),
|
||||
CHTRoot: common.HexToHash("6f48e9f101f1fac98e7d74fbbcc4fda138358271ffd974d40d2506f0308bb363"),
|
||||
BloomRoot: common.HexToHash("8242342e66e942c0cd893484e6736b9862ceb88b43ca344bb06a8285ac1b6d64"),
|
||||
},
|
||||
params.RinkebyGenesisHash: {
|
||||
name: "rinkeby",
|
||||
SectionIdx: 85,
|
||||
SectionHead: common.HexToHash("92cfa67afc4ad8ab0dcbc6fa49efd14b5b19402442e7317e6bc879d85f89d64d"),
|
||||
CHTRoot: common.HexToHash("2802ec92cd7a54a75bca96afdc666ae7b99e5d96cf8192dcfb09588812f51564"),
|
||||
BloomRoot: common.HexToHash("ebefeb31a9a42866d8cf2d2477704b4c3d7c20d0e4e9b5aaa77f396e016a1263"),
|
||||
},
|
||||
var trustedCheckpoints = map[common.Hash]*params.TrustedCheckpoint{
|
||||
params.MainnetGenesisHash: params.MainnetTrustedCheckpoint,
|
||||
params.TestnetGenesisHash: params.TestnetTrustedCheckpoint,
|
||||
params.RinkebyGenesisHash: params.RinkebyTrustedCheckpoint,
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -329,7 +302,7 @@ func (b *BloomTrieIndexerBackend) fetchMissingNodes(ctx context.Context, section
|
|||
for i := 0; i < 20; i++ {
|
||||
go func() {
|
||||
for bitIndex := range indexCh {
|
||||
r := &BloomRequest{BloomTrieRoot: root, BloomTrieNum: section - 1, BitIdx: bitIndex, SectionIdxList: []uint64{section - 1}, Config: b.odr.IndexerConfig()}
|
||||
r := &BloomRequest{BloomTrieRoot: root, BloomTrieNum: section - 1, BitIdx: bitIndex, SectionIndexList: []uint64{section - 1}, Config: b.odr.IndexerConfig()}
|
||||
for {
|
||||
if err := b.odr.Retrieve(ctx, r); err == ErrNoPeers {
|
||||
// if there are no peers to serve, retry later
|
||||
|
|
|
@ -17,9 +17,6 @@ type EWMA interface {
|
|||
|
||||
// NewEWMA constructs a new EWMA with the given alpha.
|
||||
func NewEWMA(alpha float64) EWMA {
|
||||
if !Enabled {
|
||||
return NilEWMA{}
|
||||
}
|
||||
return &StandardEWMA{alpha: alpha}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,17 @@ func GetOrRegisterMeter(name string, r Registry) Meter {
|
|||
return r.GetOrRegister(name, NewMeter).(Meter)
|
||||
}
|
||||
|
||||
// GetOrRegisterMeterForced returns an existing Meter or constructs and registers a
|
||||
// new StandardMeter no matter the global switch is enabled or not.
|
||||
// Be sure to unregister the meter from the registry once it is of no use to
|
||||
// allow for garbage collection.
|
||||
func GetOrRegisterMeterForced(name string, r Registry) Meter {
|
||||
if nil == r {
|
||||
r = DefaultRegistry
|
||||
}
|
||||
return r.GetOrRegister(name, NewMeterForced).(Meter)
|
||||
}
|
||||
|
||||
// NewMeter constructs a new StandardMeter and launches a goroutine.
|
||||
// Be sure to call Stop() once the meter is of no use to allow for garbage collection.
|
||||
func NewMeter() Meter {
|
||||
|
@ -46,8 +57,23 @@ func NewMeter() Meter {
|
|||
return m
|
||||
}
|
||||
|
||||
// NewMeter constructs and registers a new StandardMeter and launches a
|
||||
// goroutine.
|
||||
// NewMeterForced constructs a new StandardMeter and launches a goroutine no matter
|
||||
// the global switch is enabled or not.
|
||||
// Be sure to call Stop() once the meter is of no use to allow for garbage collection.
|
||||
func NewMeterForced() Meter {
|
||||
m := newStandardMeter()
|
||||
arbiter.Lock()
|
||||
defer arbiter.Unlock()
|
||||
arbiter.meters[m] = struct{}{}
|
||||
if !arbiter.started {
|
||||
arbiter.started = true
|
||||
go arbiter.tick()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// NewRegisteredMeter constructs and registers a new StandardMeter
|
||||
// and launches a goroutine.
|
||||
// Be sure to unregister the meter from the registry once it is of no use to
|
||||
// allow for garbage collection.
|
||||
func NewRegisteredMeter(name string, r Registry) Meter {
|
||||
|
@ -59,6 +85,19 @@ func NewRegisteredMeter(name string, r Registry) Meter {
|
|||
return c
|
||||
}
|
||||
|
||||
// NewRegisteredMeterForced constructs and registers a new StandardMeter
|
||||
// and launches a goroutine no matter the global switch is enabled or not.
|
||||
// Be sure to unregister the meter from the registry once it is of no use to
|
||||
// allow for garbage collection.
|
||||
func NewRegisteredMeterForced(name string, r Registry) Meter {
|
||||
c := NewMeterForced()
|
||||
if nil == r {
|
||||
r = DefaultRegistry
|
||||
}
|
||||
r.Register(name, c)
|
||||
return c
|
||||
}
|
||||
|
||||
// MeterSnapshot is a read-only copy of another Meter.
|
||||
type MeterSnapshot struct {
|
||||
count int64
|
||||
|
|
|
@ -52,13 +52,13 @@ type Miner struct {
|
|||
shouldStart int32 // should start indicates whether we should start after sync
|
||||
}
|
||||
|
||||
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64) *Miner {
|
||||
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(block *types.Block) bool) *Miner {
|
||||
miner := &Miner{
|
||||
eth: eth,
|
||||
mux: mux,
|
||||
engine: engine,
|
||||
exitCh: make(chan struct{}),
|
||||
worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil),
|
||||
worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil, isLocalBlock),
|
||||
canStart: 1,
|
||||
}
|
||||
go miner.update()
|
||||
|
|
|
@ -149,9 +149,10 @@ type worker struct {
|
|||
resubmitIntervalCh chan time.Duration
|
||||
resubmitAdjustCh chan *intervalAdjust
|
||||
|
||||
current *environment // An environment for current running cycle.
|
||||
possibleUncles map[common.Hash]*types.Block // A set of side blocks as the possible uncle blocks.
|
||||
unconfirmed *unconfirmedBlocks // A set of locally mined blocks pending canonicalness confirmations.
|
||||
current *environment // An environment for current running cycle.
|
||||
localUncles map[common.Hash]*types.Block // A set of side blocks generated locally as the possible uncle blocks.
|
||||
remoteUncles map[common.Hash]*types.Block // A set of side blocks as the possible uncle blocks.
|
||||
unconfirmed *unconfirmedBlocks // A set of locally mined blocks pending canonicalness confirmations.
|
||||
|
||||
mu sync.RWMutex // The lock used to protect the coinbase and extra fields
|
||||
coinbase common.Address
|
||||
|
@ -168,6 +169,9 @@ type worker struct {
|
|||
running int32 // The indicator whether the consensus engine is running or not.
|
||||
newTxs int32 // New arrival transaction count since last sealing work submitting.
|
||||
|
||||
// External functions
|
||||
isLocalBlock func(block *types.Block) bool // Function used to determine whether the specified block is mined by local miner.
|
||||
|
||||
// Test hooks
|
||||
newTaskHook func(*task) // Method to call upon receiving a new sealing task.
|
||||
skipSealHook func(*task) bool // Method to decide whether skipping the sealing.
|
||||
|
@ -175,7 +179,7 @@ type worker struct {
|
|||
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
||||
}
|
||||
|
||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64) *worker {
|
||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool) *worker {
|
||||
worker := &worker{
|
||||
config: config,
|
||||
engine: engine,
|
||||
|
@ -184,7 +188,9 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
|
|||
chain: eth.BlockChain(),
|
||||
gasFloor: gasFloor,
|
||||
gasCeil: gasCeil,
|
||||
possibleUncles: make(map[common.Hash]*types.Block),
|
||||
isLocalBlock: isLocalBlock,
|
||||
localUncles: make(map[common.Hash]*types.Block),
|
||||
remoteUncles: make(map[common.Hash]*types.Block),
|
||||
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
|
||||
pendingTasks: make(map[common.Hash]*task),
|
||||
txsCh: make(chan core.NewTxsEvent, txChanSize),
|
||||
|
@ -405,11 +411,19 @@ func (w *worker) mainLoop() {
|
|||
w.commitNewWork(req.interrupt, req.noempty, req.timestamp)
|
||||
|
||||
case ev := <-w.chainSideCh:
|
||||
if _, exist := w.possibleUncles[ev.Block.Hash()]; exist {
|
||||
// Short circuit for duplicate side blocks
|
||||
if _, exist := w.localUncles[ev.Block.Hash()]; exist {
|
||||
continue
|
||||
}
|
||||
// Add side block to possible uncle block set.
|
||||
w.possibleUncles[ev.Block.Hash()] = ev.Block
|
||||
if _, exist := w.remoteUncles[ev.Block.Hash()]; exist {
|
||||
continue
|
||||
}
|
||||
// Add side block to possible uncle block set depending on the author.
|
||||
if w.isLocalBlock != nil && w.isLocalBlock(ev.Block) {
|
||||
w.localUncles[ev.Block.Hash()] = ev.Block
|
||||
} else {
|
||||
w.remoteUncles[ev.Block.Hash()] = ev.Block
|
||||
}
|
||||
// If our mining block contains less than 2 uncle blocks,
|
||||
// add the new uncle block if valid and regenerate a mining block.
|
||||
if w.isRunning() && w.current != nil && w.current.uncles.Cardinality() < 2 {
|
||||
|
@ -421,7 +435,10 @@ func (w *worker) mainLoop() {
|
|||
if !ok {
|
||||
return false
|
||||
}
|
||||
uncle, exist := w.possibleUncles[hash]
|
||||
uncle, exist := w.localUncles[hash]
|
||||
if !exist {
|
||||
uncle, exist = w.remoteUncles[hash]
|
||||
}
|
||||
if !exist {
|
||||
return false
|
||||
}
|
||||
|
@ -651,7 +668,10 @@ func (w *worker) updateSnapshot() {
|
|||
if !ok {
|
||||
return false
|
||||
}
|
||||
uncle, exist := w.possibleUncles[hash]
|
||||
uncle, exist := w.localUncles[hash]
|
||||
if !exist {
|
||||
uncle, exist = w.remoteUncles[hash]
|
||||
}
|
||||
if !exist {
|
||||
return false
|
||||
}
|
||||
|
@ -859,23 +879,29 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||
misc.ApplyDAOHardFork(env.state)
|
||||
}
|
||||
// Accumulate the uncles for the current block
|
||||
for hash, uncle := range w.possibleUncles {
|
||||
if uncle.NumberU64()+staleThreshold <= header.Number.Uint64() {
|
||||
delete(w.possibleUncles, hash)
|
||||
}
|
||||
}
|
||||
uncles := make([]*types.Header, 0, 2)
|
||||
for hash, uncle := range w.possibleUncles {
|
||||
if len(uncles) == 2 {
|
||||
break
|
||||
commitUncles := func(blocks map[common.Hash]*types.Block) {
|
||||
// Clean up stale uncle blocks first
|
||||
for hash, uncle := range blocks {
|
||||
if uncle.NumberU64()+staleThreshold <= header.Number.Uint64() {
|
||||
delete(blocks, hash)
|
||||
}
|
||||
}
|
||||
if err := w.commitUncle(env, uncle.Header()); err != nil {
|
||||
log.Trace("Possible uncle rejected", "hash", hash, "reason", err)
|
||||
} else {
|
||||
log.Debug("Committing new uncle to block", "hash", hash)
|
||||
uncles = append(uncles, uncle.Header())
|
||||
for hash, uncle := range blocks {
|
||||
if len(uncles) == 2 {
|
||||
break
|
||||
}
|
||||
if err := w.commitUncle(env, uncle.Header()); err != nil {
|
||||
log.Trace("Possible uncle rejected", "hash", hash, "reason", err)
|
||||
} else {
|
||||
log.Debug("Committing new uncle to block", "hash", hash)
|
||||
uncles = append(uncles, uncle.Header())
|
||||
}
|
||||
}
|
||||
}
|
||||
// Prefer to locally generated uncle
|
||||
commitUncles(w.localUncles)
|
||||
commitUncles(w.remoteUncles)
|
||||
|
||||
if !noempty {
|
||||
// Create an empty block based on temporary copied state for sealing in advance without waiting block
|
||||
|
|
|
@ -138,7 +138,9 @@ func (ec *EthereumClient) SubscribeNewHead(ctx *Context, handler NewHeadHandler,
|
|||
handler.OnNewHead(&Header{header})
|
||||
|
||||
case err := <-rawSub.Err():
|
||||
handler.OnError(err.Error())
|
||||
if err != nil {
|
||||
handler.OnError(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +229,9 @@ func (ec *EthereumClient) SubscribeFilterLogs(ctx *Context, query *FilterQuery,
|
|||
handler.OnFilterLogs(&Log{&log})
|
||||
|
||||
case err := <-rawSub.Err():
|
||||
handler.OnError(err.Error())
|
||||
if err != nil {
|
||||
handler.OnError(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,195 @@
|
|||
// Copyright 2017 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// Contains a wrapper for the Whisper client.
|
||||
|
||||
package geth
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/whisper/shhclient"
|
||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
||||
)
|
||||
|
||||
// WhisperClient provides access to the Ethereum APIs.
|
||||
type WhisperClient struct {
|
||||
client *shhclient.Client
|
||||
}
|
||||
|
||||
// NewWhisperClient connects a client to the given URL.
|
||||
func NewWhisperClient(rawurl string) (client *WhisperClient, _ error) {
|
||||
rawClient, err := shhclient.Dial(rawurl)
|
||||
return &WhisperClient{rawClient}, err
|
||||
}
|
||||
|
||||
// GetVersion returns the Whisper sub-protocol version.
|
||||
func (wc *WhisperClient) GetVersion(ctx *Context) (version string, _ error) {
|
||||
return wc.client.Version(ctx.context)
|
||||
}
|
||||
|
||||
// Info returns diagnostic information about the whisper node.
|
||||
func (wc *WhisperClient) GetInfo(ctx *Context) (info *Info, _ error) {
|
||||
rawInfo, err := wc.client.Info(ctx.context)
|
||||
return &Info{&rawInfo}, err
|
||||
}
|
||||
|
||||
// SetMaxMessageSize sets the maximal message size allowed by this node. Incoming
|
||||
// and outgoing messages with a larger size will be rejected. Whisper message size
|
||||
// can never exceed the limit imposed by the underlying P2P protocol (10 Mb).
|
||||
func (wc *WhisperClient) SetMaxMessageSize(ctx *Context, size int32) error {
|
||||
return wc.client.SetMaxMessageSize(ctx.context, uint32(size))
|
||||
}
|
||||
|
||||
// SetMinimumPoW (experimental) sets the minimal PoW required by this node.
|
||||
// This experimental function was introduced for the future dynamic adjustment of
|
||||
// PoW requirement. If the node is overwhelmed with messages, it should raise the
|
||||
// PoW requirement and notify the peers. The new value should be set relative to
|
||||
// the old value (e.g. double). The old value could be obtained via shh_info call.
|
||||
func (wc *WhisperClient) SetMinimumPoW(ctx *Context, pow float64) error {
|
||||
return wc.client.SetMinimumPoW(ctx.context, pow)
|
||||
}
|
||||
|
||||
// Marks specific peer trusted, which will allow it to send historic (expired) messages.
|
||||
// Note This function is not adding new nodes, the node needs to exists as a peer.
|
||||
func (wc *WhisperClient) MarkTrustedPeer(ctx *Context, enode string) error {
|
||||
return wc.client.MarkTrustedPeer(ctx.context, enode)
|
||||
}
|
||||
|
||||
// NewKeyPair generates a new public and private key pair for message decryption and encryption.
|
||||
// It returns an identifier that can be used to refer to the key.
|
||||
func (wc *WhisperClient) NewKeyPair(ctx *Context) (string, error) {
|
||||
return wc.client.NewKeyPair(ctx.context)
|
||||
}
|
||||
|
||||
// AddPrivateKey stored the key pair, and returns its ID.
|
||||
func (wc *WhisperClient) AddPrivateKey(ctx *Context, key []byte) (string, error) {
|
||||
return wc.client.AddPrivateKey(ctx.context, key)
|
||||
}
|
||||
|
||||
// DeleteKeyPair delete the specifies key.
|
||||
func (wc *WhisperClient) DeleteKeyPair(ctx *Context, id string) (string, error) {
|
||||
return wc.client.DeleteKeyPair(ctx.context, id)
|
||||
}
|
||||
|
||||
// HasKeyPair returns an indication if the node has a private key or
|
||||
// key pair matching the given ID.
|
||||
func (wc *WhisperClient) HasKeyPair(ctx *Context, id string) (bool, error) {
|
||||
return wc.client.HasKeyPair(ctx.context, id)
|
||||
}
|
||||
|
||||
// GetPublicKey return the public key for a key ID.
|
||||
func (wc *WhisperClient) GetPublicKey(ctx *Context, id string) ([]byte, error) {
|
||||
return wc.client.PublicKey(ctx.context, id)
|
||||
}
|
||||
|
||||
// GetPrivateKey return the private key for a key ID.
|
||||
func (wc *WhisperClient) GetPrivateKey(ctx *Context, id string) ([]byte, error) {
|
||||
return wc.client.PrivateKey(ctx.context, id)
|
||||
}
|
||||
|
||||
// NewSymmetricKey generates a random symmetric key and returns its identifier.
|
||||
// Can be used encrypting and decrypting messages where the key is known to both parties.
|
||||
func (wc *WhisperClient) NewSymmetricKey(ctx *Context) (string, error) {
|
||||
return wc.client.NewSymmetricKey(ctx.context)
|
||||
}
|
||||
|
||||
// AddSymmetricKey stores the key, and returns its identifier.
|
||||
func (wc *WhisperClient) AddSymmetricKey(ctx *Context, key []byte) (string, error) {
|
||||
return wc.client.AddSymmetricKey(ctx.context, key)
|
||||
}
|
||||
|
||||
// GenerateSymmetricKeyFromPassword generates the key from password, stores it, and returns its identifier.
|
||||
func (wc *WhisperClient) GenerateSymmetricKeyFromPassword(ctx *Context, passwd string) (string, error) {
|
||||
return wc.client.GenerateSymmetricKeyFromPassword(ctx.context, passwd)
|
||||
}
|
||||
|
||||
// HasSymmetricKey returns an indication if the key associated with the given id is stored in the node.
|
||||
func (wc *WhisperClient) HasSymmetricKey(ctx *Context, id string) (bool, error) {
|
||||
return wc.client.HasSymmetricKey(ctx.context, id)
|
||||
}
|
||||
|
||||
// GetSymmetricKey returns the symmetric key associated with the given identifier.
|
||||
func (wc *WhisperClient) GetSymmetricKey(ctx *Context, id string) ([]byte, error) {
|
||||
return wc.client.GetSymmetricKey(ctx.context, id)
|
||||
}
|
||||
|
||||
// DeleteSymmetricKey deletes the symmetric key associated with the given identifier.
|
||||
func (wc *WhisperClient) DeleteSymmetricKey(ctx *Context, id string) error {
|
||||
return wc.client.DeleteSymmetricKey(ctx.context, id)
|
||||
}
|
||||
|
||||
// Post a message onto the network.
|
||||
func (wc *WhisperClient) Post(ctx *Context, message *NewMessage) (string, error) {
|
||||
return wc.client.Post(ctx.context, *message.newMessage)
|
||||
}
|
||||
|
||||
// NewHeadHandler is a client-side subscription callback to invoke on events and
|
||||
// subscription failure.
|
||||
type NewMessageHandler interface {
|
||||
OnNewMessage(message *Message)
|
||||
OnError(failure string)
|
||||
}
|
||||
|
||||
// SubscribeMessages subscribes to messages that match the given criteria. This method
|
||||
// is only supported on bi-directional connections such as websockets and IPC.
|
||||
// NewMessageFilter uses polling and is supported over HTTP.
|
||||
func (wc *WhisperClient) SubscribeMessages(ctx *Context, criteria *Criteria, handler NewMessageHandler, buffer int) (*Subscription, error) {
|
||||
// Subscribe to the event internally
|
||||
ch := make(chan *whisper.Message, buffer)
|
||||
rawSub, err := wc.client.SubscribeMessages(ctx.context, *criteria.criteria, ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Start up a dispatcher to feed into the callback
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case message := <-ch:
|
||||
handler.OnNewMessage(&Message{message})
|
||||
|
||||
case err := <-rawSub.Err():
|
||||
if err != nil {
|
||||
handler.OnError(err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return &Subscription{rawSub}, nil
|
||||
}
|
||||
|
||||
// NewMessageFilter creates a filter within the node. This filter can be used to poll
|
||||
// for new messages (see FilterMessages) that satisfy the given criteria. A filter can
|
||||
// timeout when it was polled for in whisper.filterTimeout.
|
||||
func (wc *WhisperClient) NewMessageFilter(ctx *Context, criteria *Criteria) (string, error) {
|
||||
return wc.client.NewMessageFilter(ctx.context, *criteria.criteria)
|
||||
}
|
||||
|
||||
// DeleteMessageFilter removes the filter associated with the given id.
|
||||
func (wc *WhisperClient) DeleteMessageFilter(ctx *Context, id string) error {
|
||||
return wc.client.DeleteMessageFilter(ctx.context, id)
|
||||
}
|
||||
|
||||
// GetFilterMessages retrieves all messages that are received between the last call to
|
||||
// this function and match the criteria that where given when the filter was created.
|
||||
func (wc *WhisperClient) GetFilterMessages(ctx *Context, id string) (*Messages, error) {
|
||||
rawFilterMessages, err := wc.client.FilterMessages(ctx.context, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res := make([]*whisper.Message, len(rawFilterMessages))
|
||||
copy(res, rawFilterMessages)
|
||||
return &Messages{res}, nil
|
||||
}
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
|
||||
)
|
||||
|
||||
// A Nonce is a 64-bit hash which proves (combined with the mix-hash) that
|
||||
|
@ -334,3 +335,95 @@ func (r *Receipt) GetLogs() *Logs { return &Logs{r.receipt.Logs} }
|
|||
func (r *Receipt) GetTxHash() *Hash { return &Hash{r.receipt.TxHash} }
|
||||
func (r *Receipt) GetContractAddress() *Address { return &Address{r.receipt.ContractAddress} }
|
||||
func (r *Receipt) GetGasUsed() int64 { return int64(r.receipt.GasUsed) }
|
||||
|
||||
// Info represents a diagnostic information about the whisper node.
|
||||
type Info struct {
|
||||
info *whisper.Info
|
||||
}
|
||||
|
||||
// NewMessage represents a new whisper message that is posted through the RPC.
|
||||
type NewMessage struct {
|
||||
newMessage *whisper.NewMessage
|
||||
}
|
||||
|
||||
func NewNewMessage() *NewMessage {
|
||||
nm := &NewMessage{
|
||||
newMessage: new(whisper.NewMessage),
|
||||
}
|
||||
return nm
|
||||
}
|
||||
|
||||
func (nm *NewMessage) GetSymKeyID() string { return nm.newMessage.SymKeyID }
|
||||
func (nm *NewMessage) SetSymKeyID(symKeyID string) { nm.newMessage.SymKeyID = symKeyID }
|
||||
func (nm *NewMessage) GetPublicKey() []byte { return nm.newMessage.PublicKey }
|
||||
func (nm *NewMessage) SetPublicKey(publicKey []byte) {
|
||||
nm.newMessage.PublicKey = common.CopyBytes(publicKey)
|
||||
}
|
||||
func (nm *NewMessage) GetSig() string { return nm.newMessage.Sig }
|
||||
func (nm *NewMessage) SetSig(sig string) { nm.newMessage.Sig = sig }
|
||||
func (nm *NewMessage) GetTTL() int64 { return int64(nm.newMessage.TTL) }
|
||||
func (nm *NewMessage) SetTTL(ttl int64) { nm.newMessage.TTL = uint32(ttl) }
|
||||
func (nm *NewMessage) GetPayload() []byte { return nm.newMessage.Payload }
|
||||
func (nm *NewMessage) SetPayload(payload []byte) { nm.newMessage.Payload = common.CopyBytes(payload) }
|
||||
func (nm *NewMessage) GetPowTime() int64 { return int64(nm.newMessage.PowTime) }
|
||||
func (nm *NewMessage) SetPowTime(powTime int64) { nm.newMessage.PowTime = uint32(powTime) }
|
||||
func (nm *NewMessage) GetPowTarget() float64 { return nm.newMessage.PowTarget }
|
||||
func (nm *NewMessage) SetPowTarget(powTarget float64) { nm.newMessage.PowTarget = powTarget }
|
||||
func (nm *NewMessage) GetTargetPeer() string { return nm.newMessage.TargetPeer }
|
||||
func (nm *NewMessage) SetTargetPeer(targetPeer string) { nm.newMessage.TargetPeer = targetPeer }
|
||||
func (nm *NewMessage) GetTopic() []byte { return nm.newMessage.Topic[:] }
|
||||
func (nm *NewMessage) SetTopic(topic []byte) { nm.newMessage.Topic = whisper.BytesToTopic(topic) }
|
||||
|
||||
// Message represents a whisper message.
|
||||
type Message struct {
|
||||
message *whisper.Message
|
||||
}
|
||||
|
||||
func (m *Message) GetSig() []byte { return m.message.Sig }
|
||||
func (m *Message) GetTTL() int64 { return int64(m.message.TTL) }
|
||||
func (m *Message) GetTimestamp() int64 { return int64(m.message.Timestamp) }
|
||||
func (m *Message) GetPayload() []byte { return m.message.Payload }
|
||||
func (m *Message) GetPoW() float64 { return m.message.PoW }
|
||||
func (m *Message) GetHash() []byte { return m.message.Hash }
|
||||
func (m *Message) GetDst() []byte { return m.message.Dst }
|
||||
|
||||
// Messages represents an array of messages.
|
||||
type Messages struct {
|
||||
messages []*whisper.Message
|
||||
}
|
||||
|
||||
// Size returns the number of messages in the slice.
|
||||
func (m *Messages) Size() int {
|
||||
return len(m.messages)
|
||||
}
|
||||
|
||||
// Get returns the message at the given index from the slice.
|
||||
func (m *Messages) Get(index int) (message *Message, _ error) {
|
||||
if index < 0 || index >= len(m.messages) {
|
||||
return nil, errors.New("index out of bounds")
|
||||
}
|
||||
return &Message{m.messages[index]}, nil
|
||||
}
|
||||
|
||||
// Criteria holds various filter options for inbound messages.
|
||||
type Criteria struct {
|
||||
criteria *whisper.Criteria
|
||||
}
|
||||
|
||||
func NewCriteria(topic []byte) *Criteria {
|
||||
c := &Criteria{
|
||||
criteria: new(whisper.Criteria),
|
||||
}
|
||||
encodedTopic := whisper.BytesToTopic(topic)
|
||||
c.criteria.Topics = []whisper.TopicType{encodedTopic}
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Criteria) GetSymKeyID() string { return c.criteria.SymKeyID }
|
||||
func (c *Criteria) SetSymKeyID(symKeyID string) { c.criteria.SymKeyID = symKeyID }
|
||||
func (c *Criteria) GetPrivateKeyID() string { return c.criteria.PrivateKeyID }
|
||||
func (c *Criteria) SetPrivateKeyID(privateKeyID string) { c.criteria.PrivateKeyID = privateKeyID }
|
||||
func (c *Criteria) GetSig() []byte { return c.criteria.Sig }
|
||||
func (c *Criteria) SetSig(sig []byte) { c.criteria.Sig = common.CopyBytes(sig) }
|
||||
func (c *Criteria) GetMinPow() float64 { return c.criteria.MinPow }
|
||||
func (c *Criteria) SetMinPow(pow float64) { c.criteria.MinPow = pow }
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue