stellar-core
Reference implementation for the peer-to-peer agent that manages the Stellar network.
Top Related Projects
Stellar's public monorepo of go code
Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
Go implementation of the Ethereum protocol
Bitcoin Core integration/staging tree
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Algorand's official implementation in Go.
Quick Overview
Stellar-core is the backbone of the Stellar network, implementing the Stellar Consensus Protocol. It's a replicated state machine that maintains a local copy of a distributed ledger, validating and agreeing on updates to the network with other Stellar-core instances.
Pros
- Implements a fast, secure, and energy-efficient consensus mechanism
- Supports custom assets and multi-currency transactions
- Highly scalable and designed for global financial systems
- Open-source with active development and community support
Cons
- Complex system requiring significant technical expertise to run and maintain
- Dependency on a network of validators for optimal performance
- Learning curve for developers new to blockchain technology
- Limited smart contract functionality compared to some other blockchain platforms
Code Examples
- Creating a new account:
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
const sourceKeypair = StellarSdk.Keypair.fromSecret('SOURCE_SECRET_KEY');
const destinationPublicKey = 'DESTINATION_PUBLIC_KEY';
server.loadAccount(sourceKeypair.publicKey())
.then(function(sourceAccount) {
const transaction = new StellarSdk.TransactionBuilder(sourceAccount, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET
})
.addOperation(StellarSdk.Operation.createAccount({
destination: destinationPublicKey,
startingBalance: '10'
}))
.setTimeout(30)
.build();
transaction.sign(sourceKeypair);
return server.submitTransaction(transaction);
})
.then(function(result) {
console.log('Account created!');
})
.catch(function(error) {
console.error('Error:', error);
});
- Sending a payment:
const server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
const sourceKeypair = StellarSdk.Keypair.fromSecret('SOURCE_SECRET_KEY');
const destinationId = 'DESTINATION_PUBLIC_KEY';
server.loadAccount(sourceKeypair.publicKey())
.then(function(sourceAccount) {
const transaction = new StellarSdk.TransactionBuilder(sourceAccount, {
fee: StellarSdk.BASE_FEE,
networkPassphrase: StellarSdk.Networks.TESTNET
})
.addOperation(StellarSdk.Operation.payment({
destination: destinationId,
asset: StellarSdk.Asset.native(),
amount: '100'
}))
.setTimeout(30)
.build();
transaction.sign(sourceKeypair);
return server.submitTransaction(transaction);
})
.then(function(result) {
console.log('Payment sent!');
})
.catch(function(error) {
console.error('Error:', error);
});
- Creating a custom asset:
const assetCode = 'MYASSET';
const issuingAccountPublicKey = 'ISSUING_ACCOUNT_PUBLIC_KEY';
const customAsset = new StellarSdk.Asset(assetCode, issuingAccountPublicKey);
Getting Started
To get started with Stellar-core:
-
Install dependencies:
sudo apt-get update && sudo apt-get install git build-essential pkg-config autoconf automake libtool bison flex libpq-dev
-
Clone the repository:
git clone https://github.com/stellar/stellar-core.git cd stellar-core
-
Build Stellar-core:
./autogen.sh && ./configure && make
-
Run Stellar-core:
./src/stellar-core --conf /path/to/your/stellar-core.cfg
Note: You'll need to create a configuration file (stellar-core.cfg
) before running
Competitor Comparisons
Stellar's public monorepo of go code
Pros of go
- Written in Go, offering better performance and easier deployment
- More modular architecture, allowing for easier customization and extension
- Simpler codebase, potentially easier for new developers to understand and contribute
Cons of go
- Less mature and battle-tested compared to stellar-core
- Smaller community and ecosystem around the Go implementation
- May lack some advanced features or optimizations present in stellar-core
Code Comparison
stellar-core (C++):
void HerderImpl::valueExternalized(uint64 slotIndex, StellarValue const& value)
{
// ... implementation details
}
go (Go):
func (h *HerderImpl) ValueExternalized(slotIndex uint64, value StellarValue) {
// ... implementation details
}
The code comparison shows similar function signatures, but with Go's more concise syntax and type declarations. Both implementations likely handle the externalization of values in the Stellar consensus protocol, but the specific details may differ due to language features and design choices.
Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
Pros of rippled
- Higher transaction throughput and faster confirmation times
- More extensive documentation and developer resources
- Broader adoption in enterprise and financial institutions
Cons of rippled
- Less decentralized consensus mechanism
- Higher hardware requirements for running a validator node
- More complex codebase, potentially harder to contribute to
Code Comparison
rippled (C++)
bool
shouldCloseLedger(
bool anyTransactions,
std::size_t prevProposers,
std::size_t proposersClosed,
std::size_t proposersValidated,
std::chrono::milliseconds prevRoundTime,
std::chrono::milliseconds timeSincePrevClose,
std::chrono::milliseconds openTime,
std::chrono::milliseconds idleInterval)
{
// Complex decision-making logic for ledger closure
}
stellar-core (C++)
bool
LedgerManagerImpl::valueExternalized(LedgerCloseData const& ledgerData)
{
// Simpler ledger externalization process
auto header = ledgerData.getTxSet()->ledgerHeader();
closeLedger(header);
return true;
}
The code comparison shows that rippled has a more complex ledger closure mechanism, while stellar-core implements a simpler approach. This reflects the different design philosophies and consensus mechanisms of the two projects.
Go implementation of the Ethereum protocol
Pros of go-ethereum
- More extensive and active development community
- Supports smart contracts with Turing-complete programming
- Higher flexibility for decentralized applications (dApps)
Cons of go-ethereum
- Higher resource requirements for running a full node
- Slower transaction processing times
- More complex consensus mechanism (moving from PoW to PoS)
Code Comparison
go-ethereum (Ethereum):
func (s *Ethereum) Start() error {
// Start up the node itself
utils.StartNode(s.stack)
// Start the Ethereum protocol
if err := s.StartEthereum(s.config); err != nil {
return err
}
stellar-core (Stellar):
void
Application::start()
{
if (mConfig.FORCE_SCP)
{
mHerder->setTrackingSCP(true);
}
if (mPersistentState->getState(PersistentState::kForceSCPOnNextLaunch) ==
The code snippets show the start functions for both projects. go-ethereum uses Go and has a more modular approach, while stellar-core uses C++ and appears to have more direct control over the consensus mechanism.
Bitcoin Core integration/staging tree
Pros of Bitcoin
- Larger and more established community with extensive documentation
- Higher market capitalization and wider adoption
- More battle-tested security and proven track record
Cons of Bitcoin
- Slower transaction processing times
- Higher energy consumption due to Proof of Work consensus mechanism
- Less flexible for building applications on top of the blockchain
Code Comparison
Bitcoin (C++):
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
// Force block reward to zero when right shift is undefined.
if (halvings >= 64)
return 0;
Stellar Core (C++):
int64_t
Ledger::getStartingBalance(LedgerManager const& lm)
{
if (lm.getLastClosedLedgerHeader().header.ledgerVersion <= 8)
return lm.getLastMinBalance(0);
else
return 0;
Both projects use C++ as their primary language. Bitcoin focuses on managing block rewards and halving intervals, while Stellar Core deals with ledger management and balance calculations. Stellar's code appears more modular and easier to extend for additional functionality.
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Pros of Cosmos SDK
- More flexible and modular architecture, allowing for easier customization and development of diverse blockchain applications
- Supports interoperability between different blockchains through the Inter-Blockchain Communication (IBC) protocol
- Larger and more active developer community, resulting in frequent updates and improvements
Cons of Cosmos SDK
- Higher complexity and steeper learning curve for developers new to the ecosystem
- Potentially slower transaction processing compared to Stellar Core's more specialized design
- Less focus on financial applications and asset issuance, which are Stellar Core's strengths
Code Comparison
Cosmos SDK (Go):
func (app *SimApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
var genesisState GenesisState
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
}
Stellar Core (C++):
void
LedgerManagerImpl::startNewLedger()
{
auto ledger = LedgerHeaderUtils::generateLedgerHeader(mApp.getNetworkID());
ledger.ledgerSeq = 1;
ledger.previousLedgerHash = Hash{};
mCurrentLedger = std::make_shared<LedgerHeaderHistoryEntry>(ledger);
}
Algorand's official implementation in Go.
Pros of go-algorand
- Written in Go, which offers better performance and concurrency handling compared to C++
- More active development with frequent updates and contributions
- Implements a pure Proof-of-Stake consensus mechanism, which is more energy-efficient
Cons of go-algorand
- Younger project with less battle-tested codebase
- Smaller developer community and ecosystem compared to Stellar
- Less extensive documentation and learning resources available
Code Comparison
go-algorand (Algorand)
func (node *AlgorandFullNode) Start() {
node.net.Start()
node.ledger.Start()
node.agreement.Start()
node.txHandler.Start()
}
stellar-core (Stellar)
void Application::start()
{
mProcessManager->startCoreProcess();
mHerder->start();
mLedgerManager->startCatchup();
mHistoryArchiveManager->start();
}
Both codebases show similar high-level structures for starting their respective nodes, but Algorand's implementation in Go appears more concise and readable compared to Stellar's C++ code.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Stellar-core is a replicated state machine that maintains a local copy of a cryptographic ledger and processes transactions against it, in consensus with a set of peers. It implements the Stellar Consensus Protocol, a federated consensus protocol. It is written in C++17 and runs on Linux, OSX and Windows. Learn more by reading the overview document.
Documentation
Documentation of the code's layout and abstractions, as well as for the
functionality available, can be found in
./docs
.
Installation
See Installation
Contributing
See Contributing
Running tests
See running tests
Top Related Projects
Stellar's public monorepo of go code
Decentralized cryptocurrency blockchain daemon implementing the XRP Ledger protocol in C++
Go implementation of the Ethereum protocol
Bitcoin Core integration/staging tree
:chains: A Framework for Building High Value Public Blockchains :sparkles:
Algorand's official implementation in Go.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot