mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
bug fixes in binary
This commit is contained in:
parent
04eb07c26f
commit
dca79ab5c1
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.swp
|
*.swp
|
||||||
|
.bak
|
||||||
|
23
accounts/account.go
Normal file
23
accounts/account.go
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package accounts
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/tendermint/tendermint/binary"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Account struct {
|
||||||
|
Name String
|
||||||
|
PubKey ByteSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Account) Verify(msg ByteSlice, sig ByteSlice) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type MyAccount struct {
|
||||||
|
Account
|
||||||
|
PrivKey ByteSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *MyAccount) Sign(msg ByteSlice) ByteSlice {
|
||||||
|
return nil
|
||||||
|
}
|
@ -50,7 +50,7 @@ func ReadByteSliceSafe(r io.Reader) (ByteSlice, error) {
|
|||||||
|
|
||||||
func ReadByteSlice(r io.Reader) ByteSlice {
|
func ReadByteSlice(r io.Reader) ByteSlice {
|
||||||
bytes, err := ReadByteSliceSafe(r)
|
bytes, err := ReadByteSliceSafe(r)
|
||||||
if r != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return bytes
|
return bytes
|
||||||
|
@ -47,7 +47,7 @@ func ReadStringSafe(r io.Reader) (String, error) {
|
|||||||
|
|
||||||
func ReadString(r io.Reader) String {
|
func ReadString(r io.Reader) String {
|
||||||
str, err := ReadStringSafe(r)
|
str, err := ReadStringSafe(r)
|
||||||
if r != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
|
167
blocks/codec_test.go
Normal file
167
blocks/codec_test.go
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
package blocks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/gob"
|
||||||
|
"encoding/json"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
. "github.com/tendermint/tendermint/binary"
|
||||||
|
"github.com/ugorji/go/codec"
|
||||||
|
"github.com/vmihailenco/msgpack"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkTestCustom(b *testing.B) {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
h := &Header{
|
||||||
|
Name: "Header",
|
||||||
|
Height: 123,
|
||||||
|
Fees: 123,
|
||||||
|
Time: 123,
|
||||||
|
PrevHash: ByteSlice("prevhash"),
|
||||||
|
ValidationHash: ByteSlice("validationhash"),
|
||||||
|
DataHash: ByteSlice("datahash"),
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
h.WriteTo(buf)
|
||||||
|
h2 := ReadHeader(buf)
|
||||||
|
if h2.Name != "Header" {
|
||||||
|
b.Fatalf("wrong name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type HHeader struct {
|
||||||
|
Name string `json:"N"`
|
||||||
|
Height uint64 `json:"H"`
|
||||||
|
Fees uint64 `json:"F"`
|
||||||
|
Time uint64 `json:"T"`
|
||||||
|
PrevHash []byte `json:"PH"`
|
||||||
|
ValidationHash []byte `json:"VH"`
|
||||||
|
DataHash []byte `json:"DH"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTestJSON(b *testing.B) {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
h := &HHeader{
|
||||||
|
Name: "Header",
|
||||||
|
Height: 123,
|
||||||
|
Fees: 123,
|
||||||
|
Time: 123,
|
||||||
|
PrevHash: []byte("prevhash"),
|
||||||
|
ValidationHash: []byte("validationhash"),
|
||||||
|
DataHash: []byte("datahash"),
|
||||||
|
}
|
||||||
|
h2 := &HHeader{}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
enc := json.NewEncoder(buf)
|
||||||
|
dec := json.NewDecoder(buf)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
enc.Encode(h)
|
||||||
|
dec.Decode(h2)
|
||||||
|
if h2.Name != "Header" {
|
||||||
|
b.Fatalf("wrong name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTestGob(b *testing.B) {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
h := &Header{
|
||||||
|
Name: "Header",
|
||||||
|
Height: 123,
|
||||||
|
Fees: 123,
|
||||||
|
Time: 123,
|
||||||
|
PrevHash: []byte("prevhash"),
|
||||||
|
ValidationHash: []byte("validationhash"),
|
||||||
|
DataHash: []byte("datahash"),
|
||||||
|
}
|
||||||
|
h2 := &Header{}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
enc := gob.NewEncoder(buf)
|
||||||
|
dec := gob.NewDecoder(buf)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
enc.Encode(h)
|
||||||
|
dec.Decode(h2)
|
||||||
|
if h2.Name != "Header" {
|
||||||
|
b.Fatalf("wrong name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTestMsgPack(b *testing.B) {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
var mh codec.MsgpackHandle
|
||||||
|
handle := &mh
|
||||||
|
|
||||||
|
h := &Header{
|
||||||
|
Name: "Header",
|
||||||
|
Height: 123,
|
||||||
|
Fees: 123,
|
||||||
|
Time: 123,
|
||||||
|
PrevHash: []byte("prevhash"),
|
||||||
|
ValidationHash: []byte("validationhash"),
|
||||||
|
DataHash: []byte("datahash"),
|
||||||
|
}
|
||||||
|
h2 := &Header{}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
enc := codec.NewEncoder(buf, handle)
|
||||||
|
dec := codec.NewDecoder(buf, handle)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
enc.Encode(h)
|
||||||
|
dec.Decode(h2)
|
||||||
|
if h2.Name != "Header" {
|
||||||
|
b.Fatalf("wrong name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTestMsgPack2(b *testing.B) {
|
||||||
|
b.StopTimer()
|
||||||
|
|
||||||
|
h := &Header{
|
||||||
|
Name: "Header",
|
||||||
|
Height: 123,
|
||||||
|
Fees: 123,
|
||||||
|
Time: 123,
|
||||||
|
PrevHash: []byte("prevhash"),
|
||||||
|
ValidationHash: []byte("validationhash"),
|
||||||
|
DataHash: []byte("datahash"),
|
||||||
|
}
|
||||||
|
h2 := &Header{}
|
||||||
|
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
enc := msgpack.NewEncoder(buf)
|
||||||
|
dec := msgpack.NewDecoder(buf)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
enc.Encode(h)
|
||||||
|
dec.Decode(h2)
|
||||||
|
if h2.Name != "Header" {
|
||||||
|
b.Fatalf("wrong name")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,15 +13,14 @@ import (
|
|||||||
//"encoding/hex"
|
//"encoding/hex"
|
||||||
)
|
)
|
||||||
|
|
||||||
var APP_DIR = os.Getenv("HOME") + "/.tendermint"
|
|
||||||
|
|
||||||
/* Global & initialization */
|
/* Global & initialization */
|
||||||
|
|
||||||
|
var AppDir = os.Getenv("HOME") + "/.tendermint"
|
||||||
var Config Config_
|
var Config Config_
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
configFile := APP_DIR + "/config.json"
|
configFile := AppDir + "/config.json"
|
||||||
|
|
||||||
// try to read configuration. if missing, write default
|
// try to read configuration. if missing, write default
|
||||||
configBytes, err := ioutil.ReadFile(configFile)
|
configBytes, err := ioutil.ReadFile(configFile)
|
||||||
@ -51,7 +50,7 @@ var defaultConfig = Config_{
|
|||||||
Port: 8770,
|
Port: 8770,
|
||||||
Db: DbConfig{
|
Db: DbConfig{
|
||||||
Type: "level",
|
Type: "level",
|
||||||
Dir: APP_DIR + "/data",
|
Dir: AppDir + "/data",
|
||||||
},
|
},
|
||||||
Twilio: TwilioConfig{},
|
Twilio: TwilioConfig{},
|
||||||
}
|
}
|
||||||
@ -92,7 +91,7 @@ func (cfg *Config_) validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Config_) bytes() []byte {
|
func (cfg *Config_) bytes() []byte {
|
||||||
configBytes, err := json.Marshal(cfg)
|
configBytes, err := json.MarshalIndent(cfg, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
30
log.go
Normal file
30
log.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cihub/seelog"
|
||||||
|
"github.com/tendermint/tendermint/p2p"
|
||||||
|
)
|
||||||
|
|
||||||
|
var log seelog.LoggerInterface
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// TODO: replace with configuration file in the ~/.tendermint directory.
|
||||||
|
config := `
|
||||||
|
<seelog type="asyncloop" minlevel="debug">
|
||||||
|
<outputs formatid="colored">
|
||||||
|
<console/>
|
||||||
|
</outputs>
|
||||||
|
<formats>
|
||||||
|
<format id="main" format="%Date/%Time [%LEV] %Msg%n"/>
|
||||||
|
<format id="colored" format="%EscM(46)%Level%EscM(49) %EscM(36)%File%EscM(39) %Msg%n%EscM(0)"/>
|
||||||
|
</formats>
|
||||||
|
</seelog>`
|
||||||
|
|
||||||
|
var err error
|
||||||
|
log, err = seelog.LoggerFromConfigAsBytes([]byte(config))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
p2p.SetLogger(log)
|
||||||
|
}
|
73
main.go
73
main.go
@ -1,33 +1,35 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/config"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
func initPeer(peer *p2p.Peer) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Define channels for our app
|
// Define channels for our app
|
||||||
chDescs := []ChannelDescriptor{
|
chDescs := []p2p.ChannelDescriptor{
|
||||||
ChannelDescriptor{
|
p2p.ChannelDescriptor{
|
||||||
Name: "PEX",
|
Name: "PEX",
|
||||||
SendBufferSize: 2,
|
SendBufferSize: 2,
|
||||||
RecvBuffersize: 2,
|
RecvBufferSize: 2,
|
||||||
},
|
},
|
||||||
ChannelDescriptor{
|
p2p.ChannelDescriptor{
|
||||||
Name: "block",
|
Name: "block",
|
||||||
SendBufferSize: 10,
|
SendBufferSize: 10,
|
||||||
RecvBufferSize: 10,
|
RecvBufferSize: 10,
|
||||||
},
|
},
|
||||||
ChannelDescriptor{
|
p2p.ChannelDescriptor{
|
||||||
Name: "mempool",
|
Name: "mempool",
|
||||||
SendBufferSize: 100,
|
SendBufferSize: 100,
|
||||||
RecvBufferSize: 100,
|
RecvBufferSize: 100,
|
||||||
},
|
},
|
||||||
ChannelDescriptor{
|
p2p.ChannelDescriptor{
|
||||||
Name: "consensus",
|
Name: "consensus",
|
||||||
SendBufferSize: 1000,
|
SendBufferSize: 1000,
|
||||||
RecvBufferSize: 1000,
|
RecvBufferSize: 1000,
|
||||||
@ -35,19 +37,62 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the switch
|
// Create the switch
|
||||||
sw := NewSwitch(chDescs)
|
sw := p2p.NewSwitch(chDescs)
|
||||||
|
|
||||||
// Create a listener for incoming connections
|
// Create a listener for incoming connections
|
||||||
l := NewDefaultListener("tcp", ":8001")
|
l := p2p.NewDefaultListener("tcp", ":8001")
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
inConn, ok := <-l.Connections()
|
inConn, ok := <-l.Connections()
|
||||||
if !ok {
|
if !ok {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
sw.AddPeerWithConnection(inConn, false)
|
peer, err := sw.AddPeerWithConnection(inConn, false)
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("Ignoring error from incoming connection: %v\n%v",
|
||||||
|
peer, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
initPeer(peer)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// TODO
|
// Open our address book
|
||||||
|
book := p2p.NewAddrBook(config.AppDir + "/addrbook.json")
|
||||||
|
|
||||||
|
// Start PEX
|
||||||
|
go p2p.PexHandler(sw, book)
|
||||||
|
|
||||||
|
// Sleep forever
|
||||||
|
go _trapSignal()
|
||||||
|
select {}
|
||||||
|
}
|
||||||
|
|
||||||
|
func initPeer(peer *p2p.Peer) {
|
||||||
|
// TODO: ask for more peers if we need them.
|
||||||
|
}
|
||||||
|
|
||||||
|
func trapSignal() {
|
||||||
|
ch := make(chan os.Signal)
|
||||||
|
signal.Notify(ch, syscall.SIGINT)
|
||||||
|
sig := <-ch
|
||||||
|
fmt.Println("???", sig)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _trapSignal() {
|
||||||
|
// capture ctrl+c and stop CPU profiler
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt)
|
||||||
|
//signal.Notify(c, syscall.SIGINT)
|
||||||
|
go func() {
|
||||||
|
fmt.Println("inside")
|
||||||
|
for sig := range c {
|
||||||
|
fmt.Println("signal!>>", sig)
|
||||||
|
log.Infof("captured %v, stopping profiler and exiting..", sig)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
fmt.Println("inside done")
|
||||||
|
}()
|
||||||
|
fmt.Println("ok")
|
||||||
}
|
}
|
||||||
|
20
p2p/log.go
20
p2p/log.go
@ -6,22 +6,6 @@ import (
|
|||||||
|
|
||||||
var log seelog.LoggerInterface
|
var log seelog.LoggerInterface
|
||||||
|
|
||||||
func init() {
|
func SetLogger(l seelog.LoggerInterface) {
|
||||||
// TODO: replace with configuration file in the ~/.tendermint directory.
|
log = l
|
||||||
config := `
|
|
||||||
<seelog type="asyncloop" minlevel="debug">
|
|
||||||
<outputs formatid="colored">
|
|
||||||
<console/>
|
|
||||||
</outputs>
|
|
||||||
<formats>
|
|
||||||
<format id="main" format="%Date/%Time [%LEV] %Msg%n"/>
|
|
||||||
<format id="colored" format="%EscM(46)%Level%EscM(49) %EscM(36)%File%EscM(39) %Msg%n%EscM(0)"/>
|
|
||||||
</formats>
|
|
||||||
</seelog>`
|
|
||||||
|
|
||||||
var err error
|
|
||||||
log, err = seelog.LoggerFromConfigAsBytes([]byte(config))
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user