Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ integration

.idea
validators.pubs
node_modules
*.temp.*
17 changes: 17 additions & 0 deletions beacon/config/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package config

import (
"crypto/sha256"
"encoding/json"
)

// Options are bare options passed to the beacon app.
type Options struct {
RPCListen string `yaml:"rpc_listen_addr" cli:"rpclisten"`
Expand Down Expand Up @@ -189,3 +194,15 @@ var NetworkIDs = map[string]Config{
"regtest": RegtestConfig,
"testnet": MainNetConfig,
}

// HashConfig computes the hash of the config
func HashConfig(config *Config) []byte {
// Use JSON marshal instead of ssz.HashTreeRoot because ssz doesn't support type 'int'.
b, err := json.Marshal(config)
if err != nil {
// We should allow failed hash here, let's panic and exit
panic(err)
}
h := sha256.Sum256(b)
return h[:]
}
10 changes: 10 additions & 0 deletions beacon/module/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ func (app *BeaconApp) GetHostNode() *p2p.HostNode {
return app.hostNode
}

// GetBlockchain gets the block chain
func (app *BeaconApp) GetBlockchain() *beacon.Blockchain {
return app.blockchain
}

// GetSyncManager gets the syncManager
func (app *BeaconApp) GetSyncManager() *beacon.SyncManager {
return &app.syncManager
}

// Load user config from configure file
func (app *BeaconApp) loadConfig() error {
return nil
Expand Down
18 changes: 17 additions & 1 deletion beacon/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package rpc

import (
"fmt"
"github.com/prysmaticlabs/go-ssz"
"net"

"github.com/prysmaticlabs/go-ssz"

"github.com/phoreproject/synapse/p2p"
"github.com/phoreproject/synapse/utils"

"github.com/golang/protobuf/proto"

"github.com/golang/protobuf/ptypes/empty"
"github.com/phoreproject/synapse/beacon"
"github.com/phoreproject/synapse/beacon/config"
"github.com/phoreproject/synapse/chainhash"

"github.com/phoreproject/synapse/primitives"
Expand Down Expand Up @@ -176,6 +178,13 @@ func (s *server) GetEpochInformation(ctx context.Context, in *pb.EpochInformatio
state := s.chain.GetState()
config := s.chain.GetConfig()

if in.EpochIndex > s.chain.GetCurrentSlot()/s.chain.GetConfig().EpochLength-3 {
return &pb.EpochInformationResponse{
HasEpochInformation: false,
Information: nil,
}, nil
}

requestedEpochSlot := uint64(in.EpochIndex) * s.chain.GetConfig().EpochLength

if requestedEpochSlot > state.Slot {
Expand Down Expand Up @@ -334,6 +343,13 @@ func (s *server) GetValidatorInformation(ctx context.Context, in *pb.GetValidato
return validator.ToProto(), nil
}

// GetConfigHash gets the config hash
func (s *server) GetConfigHash(ctx context.Context, in *empty.Empty) (*pb.GetConfigHashResponse, error) {
return &pb.GetConfigHashResponse{
Hash: config.HashConfig(s.chain.GetConfig()),
}, nil
}

// Serve serves the RPC server
func Serve(proto string, listenAddr string, b *beacon.Blockchain, hostNode *p2p.HostNode, mempool *beacon.Mempool) error {
lis, err := net.Listen(proto, listenAddr)
Expand Down
5 changes: 5 additions & 0 deletions beacon/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (b *Blockchain) ProcessBlock(block *primitives.Block, checkTime bool, verif
initialJustifiedEpoch := initialState.JustifiedEpoch
initialFinalizedEpoch := initialState.FinalizedEpoch

if (block.BlockHeader.SlotNumber+(b.config.EpochLength-1))/b.config.EpochLength >= initialState.EpochIndex+3 {
logger.Debugf("block epoch is too far from parent")
return nil, nil, errors.New("block epoch is too far from parent")
}

receipts, newState, err := b.AddBlockToStateMap(block, verifySignature)
if err != nil {
return nil, nil, err
Expand Down
7 changes: 6 additions & 1 deletion beacon/statemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/phoreproject/synapse/chainhash"
"github.com/phoreproject/synapse/primitives"
"github.com/prysmaticlabs/go-ssz"
logger "github.com/sirupsen/logrus"
)

type stateDerivedFromBlock struct {
Expand Down Expand Up @@ -125,7 +126,11 @@ func (sm *StateManager) GetStateForHashAtSlot(blockHash chainhash.Hash, slot uin
return nil, nil, fmt.Errorf("could not find state for block %s", blockHash)
}

return derivedState.deriveState(slot, view, c)
receipts, state, err := derivedState.deriveState(slot, view, c)

logger.Debugf("derivedState.lastSlotReceipts length: %d for block: %s\n", len(derivedState.lastSlotReceipts), blockHash.String())

return receipts, state, err
}

// SetBlockState sets the state for a certain block. This SHOULD ONLY
Expand Down
3 changes: 2 additions & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package cfg
import (
"flag"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"reflect"
"strings"

"gopkg.in/yaml.v2"
)

type argInfo struct {
Expand Down
11 changes: 11 additions & 0 deletions cmd/beacon/synapsebeacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ import (
"github.com/phoreproject/synapse/cfg"
"github.com/phoreproject/synapse/utils"
logger "github.com/sirupsen/logrus"
/*
Uncomment to enable memory profiling. To use it, run synapsebeacon, then
curl -sK -v http://localhost:9000/debug/pprof/heap > heap
go tool pprof heap
or to see all allocated memory
go tool pprof --alloc_space heap
in go pprof, use 'top' command to see the top memory usage
*///"net/http"
//_ "net/http/pprof"
)

func main() {
//go http.ListenAndServe("localhost:9000", nil)

beaconConfig := config.Options{}
globalConfig := cfg.GlobalOptions{}
err := cfg.LoadFlags(&beaconConfig, &globalConfig)
Expand Down
1 change: 0 additions & 1 deletion explorer/assets/style.css

This file was deleted.

110 changes: 0 additions & 110 deletions explorer/block.go

This file was deleted.

62 changes: 4 additions & 58 deletions explorer/cmd/synapseexplorer.go
Original file line number Diff line number Diff line change
@@ -1,81 +1,27 @@
package main

import (
"flag"
"os"
"strings"

"github.com/phoreproject/synapse/p2p"
"github.com/phoreproject/synapse/utils"

"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/phoreproject/synapse/explorer"

"github.com/sirupsen/logrus"
logger "github.com/sirupsen/logrus"
)

func main() {
chainconfig := flag.String("chainconfig", "testnet.json", "file of chain config")
resync := flag.Bool("resync", false, "resyncs the blockchain if this is set")
datadir := flag.String("datadir", "", "location to store blockchain data")
initialConnections := flag.String("connect", "", "comma separated multiaddrs")
listen := flag.String("listen", "/ip4/0.0.0.0/tcp/11781", "specifies the address to listen on")

// Logging
level := flag.String("level", "info", "log level")
flag.Parse()

utils.CheckNTP()

config := explorer.LoadConfig()
changed, newLimit, err := utils.ManageFdLimit()
if err != nil {
panic(err)
}
if changed {
logrus.Infof("changed ulimit to: %d", newLimit)
}

lvl, err := logrus.ParseLevel(*level)
if err != nil {
panic(err)
}
logrus.SetLevel(lvl)

db, err := gorm.Open("sqlite3", "/tmp/gorm.db")
if err != nil {
panic(err)
}
defer db.Close()

// we should load the keys from the validator keystore
f, err := os.Open(*chainconfig)
if err != nil {
panic(err)
logger.Infof("changed ulimit to: %d", newLimit)
}

explorerConfig, err := explorer.ReadChainFileToConfig(f)
if err != nil {
panic(err)
}

err = f.Close()
if err != nil {
panic(err)
}

initialPeers, err := p2p.ParseInitialConnections(strings.Split(*initialConnections, ","))
if err != nil {
panic(err)
}

explorerConfig.DiscoveryOptions.PeerAddresses = append(explorerConfig.DiscoveryOptions.PeerAddresses, initialPeers...)

explorerConfig.DataDirectory = *datadir
explorerConfig.Resync = *resync
explorerConfig.ListeningAddress = *listen

ex, err := explorer.NewExplorer(*explorerConfig, db)
ex, err := explorer.NewExplorer(config)
if err != nil {
panic(err)
}
Expand Down
Loading