aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-09 22:09:28 +0800
committerobscuren <geffobscura@gmail.com>2014-05-09 22:09:28 +0800
commitafe83af219c2146e022f6665cf30097b582d3e79 (patch)
tree74ce21d3ea64b1a433ffb723c0171a4071e42392
parent5a0bae1dae831818740a2f20ca308c4176f5201d (diff)
downloadgo-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar.gz
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar.bz2
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar.lz
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar.xz
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.tar.zst
go-tangerine-afe83af219c2146e022f6665cf30097b582d3e79.zip
Moved seeding and moved manifest
-rw-r--r--ethchain/state.go47
-rw-r--r--ethchain/state_manager.go33
-rw-r--r--ethereum.go82
-rw-r--r--ethutil/config.go1
4 files changed, 80 insertions, 83 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 5d42c40c0..d02584d67 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -116,16 +116,6 @@ func (s *State) Copy() *State {
return NewState(s.trie.Copy())
}
-type ObjType byte
-
-const (
- NilTy ObjType = iota
- AccountTy
- ContractTy
-
- UnknownTy
-)
-
// Updates any given state object
func (s *State) UpdateStateObject(object *StateObject) {
addr := object.Address()
@@ -145,3 +135,40 @@ func (s *State) Put(key, object []byte) {
func (s *State) Root() interface{} {
return s.trie.Root
}
+
+// Object manifest
+//
+// The object manifest is used to keep changes to the state so we can keep track of the changes
+// that occurred during a state transitioning phase.
+type Manifest struct {
+ // XXX These will be handy in the future. Not important for now.
+ objectAddresses map[string]bool
+ storageAddresses map[string]map[string]bool
+
+ objectChanges map[string]*StateObject
+ storageChanges map[string]map[string]*big.Int
+}
+
+func NewManifest() *Manifest {
+ m := &Manifest{objectAddresses: make(map[string]bool), storageAddresses: make(map[string]map[string]bool)}
+ m.Reset()
+
+ return m
+}
+
+func (m *Manifest) Reset() {
+ m.objectChanges = make(map[string]*StateObject)
+ m.storageChanges = make(map[string]map[string]*big.Int)
+}
+
+func (m *Manifest) AddObjectChange(stateObject *StateObject) {
+ m.objectChanges[string(stateObject.Address())] = stateObject
+}
+
+func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte, storage *big.Int) {
+ if m.storageChanges[string(stateObject.Address())] == nil {
+ m.storageChanges[string(stateObject.Address())] = make(map[string]*big.Int)
+ }
+
+ m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
+}
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 9ab378b67..dd21a31b1 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -331,36 +331,3 @@ func (sm *StateManager) notifyChanges() {
}
}
}
-
-type Manifest struct {
- // XXX These will be handy in the future. Not important for now.
- objectAddresses map[string]bool
- storageAddresses map[string]map[string]bool
-
- objectChanges map[string]*StateObject
- storageChanges map[string]map[string]*big.Int
-}
-
-func NewManifest() *Manifest {
- m := &Manifest{objectAddresses: make(map[string]bool), storageAddresses: make(map[string]map[string]bool)}
- m.Reset()
-
- return m
-}
-
-func (m *Manifest) Reset() {
- m.objectChanges = make(map[string]*StateObject)
- m.storageChanges = make(map[string]map[string]*big.Int)
-}
-
-func (m *Manifest) AddObjectChange(stateObject *StateObject) {
- m.objectChanges[string(stateObject.Address())] = stateObject
-}
-
-func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte, storage *big.Int) {
- if m.storageChanges[string(stateObject.Address())] == nil {
- m.storageChanges[string(stateObject.Address())] = make(map[string]*big.Int)
- }
-
- m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
-}
diff --git a/ethereum.go b/ethereum.go
index 2f4db7336..e3140b5ce 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -253,7 +253,7 @@ func (s *Ethereum) ReapDeadPeerHandler() {
}
// Start the ethereum
-func (s *Ethereum) Start() {
+func (s *Ethereum) Start(seed bool) {
// Bind to addr and port
ln, err := net.Listen("tcp", ":"+s.Port)
if err != nil {
@@ -272,47 +272,51 @@ func (s *Ethereum) Start() {
// Start the reaping processes
go s.ReapDeadPeerHandler()
- if ethutil.Config.Seed {
- ethutil.Config.Log.Debugln("Seeding")
- // DNS Bootstrapping
- _, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org")
- if err == nil {
- peers := []string{}
- // Iterate SRV nodes
- for _, n := range nodes {
- target := n.Target
- port := strconv.Itoa(int(n.Port))
- // Resolve target to ip (Go returns list, so may resolve to multiple ips?)
- addr, err := net.LookupHost(target)
- if err == nil {
- for _, a := range addr {
- // Build string out of SRV port and Resolved IP
- peer := net.JoinHostPort(a, port)
- log.Println("Found DNS Bootstrap Peer:", peer)
- peers = append(peers, peer)
- }
- } else {
- log.Println("Couldn't resolve :", target)
+ if seed {
+ s.Seed()
+ }
+}
+
+func (s *Ethereum) Seed() {
+ ethutil.Config.Log.Debugln("Seeding")
+ // DNS Bootstrapping
+ _, nodes, err := net.LookupSRV("eth", "tcp", "ethereum.org")
+ if err == nil {
+ peers := []string{}
+ // Iterate SRV nodes
+ for _, n := range nodes {
+ target := n.Target
+ port := strconv.Itoa(int(n.Port))
+ // Resolve target to ip (Go returns list, so may resolve to multiple ips?)
+ addr, err := net.LookupHost(target)
+ if err == nil {
+ for _, a := range addr {
+ // Build string out of SRV port and Resolved IP
+ peer := net.JoinHostPort(a, port)
+ log.Println("Found DNS Bootstrap Peer:", peer)
+ peers = append(peers, peer)
}
+ } else {
+ log.Println("Couldn't resolve :", target)
}
- // Connect to Peer list
- s.ProcessPeerList(peers)
- } else {
- // Fallback to servers.poc3.txt
- resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
- if err != nil {
- log.Println("Fetching seed failed:", err)
- return
- }
- defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
- if err != nil {
- log.Println("Reading seed failed:", err)
- return
- }
-
- s.ConnectToPeer(string(body))
}
+ // Connect to Peer list
+ s.ProcessPeerList(peers)
+ } else {
+ // Fallback to servers.poc3.txt
+ resp, err := http.Get("http://www.ethereum.org/servers.poc3.txt")
+ if err != nil {
+ log.Println("Fetching seed failed:", err)
+ return
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ log.Println("Reading seed failed:", err)
+ return
+ }
+
+ s.ConnectToPeer(string(body))
}
}
diff --git a/ethutil/config.go b/ethutil/config.go
index 382396ceb..db07e1d18 100644
--- a/ethutil/config.go
+++ b/ethutil/config.go
@@ -27,7 +27,6 @@ type config struct {
Ver string
ClientString string
Pubkey []byte
- Seed bool
}
var Config *config