-
Notifications
You must be signed in to change notification settings - Fork 20k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2620c98
commit 7e94f76
Showing
372 changed files
with
49,655 additions
and
2,832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package log | ||
|
||
const ( | ||
TxCreated = "TX-CREATED" | ||
TxAccepted = "TX-ACCEPTED" | ||
BecameMinter = "BECAME-MINTER" | ||
BecameVerifier = "BECAME-VERIFIER" | ||
BlockCreated = "BLOCK-CREATED" | ||
BlockVotingStarted = "BLOCK-VOTING-STARTED" | ||
) | ||
|
||
var DoEmitCheckpoints = false | ||
|
||
func EmitCheckpoint(checkpointName string, logValues ...interface{}) { | ||
if DoEmitCheckpoints { | ||
Info("QUORUM-CHECKPOINT", "name", checkpointName, "data", logValues) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package raft | ||
|
||
type PublicRaftAPI struct { | ||
raftService *RaftService | ||
} | ||
|
||
func NewPublicRaftAPI(raftService *RaftService) *PublicRaftAPI { | ||
return &PublicRaftAPI{raftService} | ||
} | ||
|
||
func (s *PublicRaftAPI) Role() string { | ||
return s.raftService.raftProtocolManager.NodeInfo().Role | ||
} | ||
|
||
func (s *PublicRaftAPI) AddPeer(raftId uint16, enodeId string) error { | ||
return s.raftService.raftProtocolManager.ProposeNewPeer(raftId, enodeId) | ||
} | ||
|
||
func (s *PublicRaftAPI) RemovePeer(raftId uint16) { | ||
s.raftService.raftProtocolManager.ProposePeerRemoval(raftId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package raft | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core" | ||
"github.com/ethereum/go-ethereum/eth" | ||
"github.com/ethereum/go-ethereum/ethdb" | ||
"github.com/ethereum/go-ethereum/event" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/node" | ||
"github.com/ethereum/go-ethereum/p2p" | ||
"github.com/ethereum/go-ethereum/p2p/discover" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
type RaftService struct { | ||
blockchain *core.BlockChain | ||
chainDb ethdb.Database // Block chain database | ||
txMu sync.Mutex | ||
txPool *core.TxPool | ||
accountManager *accounts.Manager | ||
|
||
raftProtocolManager *ProtocolManager | ||
startPeers []*discover.Node | ||
|
||
// we need an event mux to instantiate the blockchain | ||
eventMux *event.TypeMux | ||
minter *minter | ||
} | ||
|
||
type RaftNodeInfo struct { | ||
ClusterSize int `json:"clusterSize"` | ||
Genesis common.Hash `json:"genesis"` // SHA3 hash of the host's genesis block | ||
Head common.Hash `json:"head"` // SHA3 hash of the host's best owned block | ||
Role string `json:"role"` | ||
} | ||
|
||
func New(ctx *node.ServiceContext, chainConfig *params.ChainConfig, raftId uint16, joinExisting bool, blockTime time.Duration, e *eth.Ethereum, startPeers []*discover.Node, datadir string) (*RaftService, error) { | ||
service := &RaftService{ | ||
eventMux: ctx.EventMux, | ||
chainDb: e.ChainDb(), | ||
blockchain: e.BlockChain(), | ||
txPool: e.TxPool(), | ||
accountManager: e.AccountManager(), | ||
startPeers: startPeers, | ||
} | ||
|
||
service.minter = newMinter(chainConfig, service, blockTime) | ||
|
||
var err error | ||
if service.raftProtocolManager, err = NewProtocolManager(raftId, service.blockchain, service.eventMux, startPeers, joinExisting, datadir, service.minter); err != nil { | ||
return nil, err | ||
} | ||
|
||
return service, nil | ||
} | ||
|
||
// Backend interface methods: | ||
|
||
func (service *RaftService) AccountManager() *accounts.Manager { return service.accountManager } | ||
func (service *RaftService) BlockChain() *core.BlockChain { return service.blockchain } | ||
func (service *RaftService) ChainDb() ethdb.Database { return service.chainDb } | ||
func (service *RaftService) DappDb() ethdb.Database { return nil } | ||
func (service *RaftService) EventMux() *event.TypeMux { return service.eventMux } | ||
func (service *RaftService) TxPool() *core.TxPool { return service.txPool } | ||
|
||
// node.Service interface methods: | ||
|
||
func (service *RaftService) Protocols() []p2p.Protocol { return []p2p.Protocol{} } | ||
func (service *RaftService) APIs() []rpc.API { | ||
return []rpc.API{ | ||
{ | ||
Namespace: "raft", | ||
Version: "1.0", | ||
Service: NewPublicRaftAPI(service), | ||
Public: true, | ||
}, | ||
} | ||
} | ||
|
||
// Start implements node.Service, starting the background data propagation thread | ||
// of the protocol. | ||
func (service *RaftService) Start(p2pServer *p2p.Server) error { | ||
service.raftProtocolManager.Start(p2pServer) | ||
return nil | ||
} | ||
|
||
// Stop implements node.Service, stopping the background data propagation thread | ||
// of the protocol. | ||
func (service *RaftService) Stop() error { | ||
service.blockchain.Stop() | ||
service.raftProtocolManager.Stop() | ||
service.eventMux.Stop() | ||
|
||
service.chainDb.Close() | ||
|
||
log.Info("Raft stopped") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package raft | ||
|
||
import ( | ||
etcdRaft "github.com/coreos/etcd/raft" | ||
) | ||
|
||
const ( | ||
protocolName = "raft" | ||
protocolVersion uint64 = 0x01 | ||
|
||
raftMsg = 0x00 | ||
|
||
minterRole = etcdRaft.LEADER | ||
verifierRole = etcdRaft.NOT_LEADER | ||
|
||
// Raft's ticker interval | ||
tickerMS = 100 | ||
|
||
// We use a bounded channel of constant size buffering incoming messages | ||
msgChanSize = 1000 | ||
|
||
// Snapshot after this many raft messages | ||
// | ||
// TODO: measure and get this as low as possible without affecting performance | ||
// | ||
snapshotPeriod = 250 | ||
|
||
peerUrlKeyPrefix = "peerUrl-" | ||
) | ||
|
||
var ( | ||
appliedDbKey = []byte("applied") | ||
) |
Oops, something went wrong.