交易池子股票资金池是什么意思思?

0x00 摘要我们知道当交易被广播并且被矿工接收到时,矿工就会把交易加入到本地的交易池当中,每个矿工又会对自己的交易池设置相应的限制,来保证交易数量不会过多,矿工在打包交易到区块中时,也会根据一定的优先顺序来选择交易,从而让自己能获得尽量多的交易费。 对于交易池主要介绍两个结构CTxMemPoolEntry和CTxMemPool,第一个是交易池中每一个元素的基本结构,第二个是整个交易池包含的所有信息。0x01 CTxMemPoolEntry/**
* CTxMemPoolEntry存储交易和该交易的所有子孙交易,
* 当一个新的entry添加到mempool中时,我们更新它的所有子孙状态
* 和祖先状态
*/
class CTxMemPoolEntry
{
private:
CTransactionRef tx;
// 交易引用
CAmount nFee;
//交易费用
//!< Cached to avoid expensive parent-transaction lookups
size_t nTxWeight;
//!< ... and avoid recomputing tx weight (also used for GetTxSize())
size_t nUsageSize;
//大小
//!< ... and total memory usage
int64_t nTime;
//时间戳
//!< Local time when entering the mempool
unsigned int entryHeight; //区块高度 //!< Chain height when entering the mempool
bool spendsCoinbase;
//前一个交易是否是CoinBase
int64_t sigOpCost;
//!< Total sigop cost
int64_t feeDelta;
// 调整交易的优先级
LockPoints lockPoints;
//交易最后的所在区块高度和打包的时间
// 子孙交易信息,如果我们移除一个交易,必须同时移除它的所有子孙交易
uint64_t nCountWithDescendants;
// 子孙交易的数量
uint64_t nSizeWithDescendants;
// 大小
CAmount nModFeesWithDescendants; // 费用和,包括当前交易
// 祖先交易信息
uint64_t nCountWithAncestors;
uint64_t nSizeWithAncestors;
CAmount nModFeesWithAncestors;
int64_t nSigOpCostWithAncestors;
public:
CTxMemPoolEntry(const CTransactionRef& _tx, const CAmount& _nFee,
int64_t _nTime, unsigned int _entryHeight,
bool spendsCoinbase,
int64_t nSigOpsCost, LockPoints lp);
const CTransaction& GetTx() const { return *this->tx; }
CTransactionRef GetSharedTx() const { return this->tx; }
const CAmount& GetFee() const { return nFee; }
size_t GetTxSize() const;
size_t GetTxWeight() const { return nTxWeight; }
int64_t GetTime() const { return nTime; }
unsigned int GetHeight() const { return entryHeight; }
int64_t GetSigOpCost() const { return sigOpCost; }
int64_t GetModifiedFee() const { return nFee + feeDelta; }
size_t DynamicMemoryUsage() const { return nUsageSize; }
const LockPoints& GetLockPoints() const { return lockPoints; }
// 更新子孙状态
void UpdateDescendantState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount);
// 更新祖先状态
void UpdateAncestorState(int64_t modifySize, CAmount modifyFee, int64_t modifyCount, int modifySigOps);
// 更新feeDelta,并且修改子孙交易费用
void UpdateFeeDelta(int64_t feeDelta);
// 更新LockPoint
void UpdateLockPoints(const LockPoints& lp);
uint64_t GetCountWithDescendants() const { return nCountWithDescendants; }
uint64_t GetSizeWithDescendants() const { return nSizeWithDescendants; }
CAmount GetModFeesWithDescendants() const { return nModFeesWithDescendants; }
bool GetSpendsCoinbase() const { return spendsCoinbase; }
uint64_t GetCountWithAncestors() const { return nCountWithAncestors; }
uint64_t GetSizeWithAncestors() const { return nSizeWithAncestors; }
CAmount GetModFeesWithAncestors() const { return nModFeesWithAncestors; }
int64_t GetSigOpCostWithAncestors() const { return nSigOpCostWithAncestors; }
mutable size_t vTxHashesIdx; //!< Index in mempool's vTxHashes
};123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172730x02 CTxMemPool/**
* 交易内存池,保存所有在当前主链上有效的交易。
* 当交易在网络上广播之后,就会被加进交易池。
* 但并不是所有的交易都会被加入,
* 例如交易费太小的,或者“双花”的交易或者非标准交易。
* 内存池中通过一个boost::multi_index类型的变量mapTx来排序所有交易,
* 按照下面四个标准:
* -交易hash
* -交易费(包括所有子孙交易)
* -在mempool中的时间
* -挖矿分数
* 为了保证交易费的正确性,当新交易被加进mempool时,我们必须更新
* 该交易的所有祖先交易信息,而这个操作可能会导致处理速度变慢,
* 所以必须对更需祖先的数量进行限制。
*/
class CTxMemPool
{
private:
uint32_t nCheckFrequency; //表示在2^32时间内检查的次数
unsigned int nTransactionsUpdated; //!< Used by getblocktemplate to trigger CreateNewBlock() invocation
CBlockPolicyEstimator* minerPolicyEstimator;
uint64_t totalTxSize;
//所有mempool中交易的虚拟大小,不包括见证数据
uint64_t cachedInnerUsage; //map中元素使用的动态内存大小之和
mutable int64_t lastRollingFeeUpdate;
mutable bool blockSinceLastRollingFeeBump;
mutable double rollingMinimumFeeRate; //进入pool需要的最小费用
void trackPackageRemoved(const CFeeRate& rate);
public:
static const int ROLLING_FEE_HALFLIFE = 60 * 60 * 12; // public only for testing
typedef boost::multi_index_container<
CTxMemPoolEntry,
boost::multi_index::indexed_by<
// sorted by txid, 首先根据交易hash排
boost::multi_index::hashed_unique<mempoolentry_txid, SaltedTxidHasher>,
// sorted by fee rate,然后是费用
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<descendant_score>,
boost::multi_index::identity<CTxMemPoolEntry>,
CompareTxMemPoolEntryByDescendantScore
>,
// sorted by entry time,然后时间
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<entry_time>,
boost::multi_index::identity<CTxMemPoolEntry>,
CompareTxMemPoolEntryByEntryTime
>,
// sorted by score (for mining prioritization), 分数
boost::multi_index::ordered_unique<
boost::multi_index::tag<mining_score>,
boost::multi_index::identity<CTxMemPoolEntry>,
CompareTxMemPoolEntryByScore
>,
// sorted by fee rate with ancestors, 祖先交易费
boost::multi_index::ordered_non_unique<
boost::multi_index::tag<ancestor_score>,
boost::multi_index::identity<CTxMemPoolEntry>,
CompareTxMemPoolEntryByAncestorFee
>
>
> indexed_transaction_set;
mutable CCriticalSection cs;
indexed_transaction_set mapTx;
typedef indexed_transaction_set::nth_index<0>::type::iterator txiter;
std::vector<std::pair<uint256, txiter> > vTxHashes; //所有交易见证数据的哈希
struct CompareIteratorByHash {
bool operator()(const txiter &a, const txiter &b) const {
return a->GetTx().GetHash() < b->GetTx().GetHash();
}
};
typedef std::set<txiter, CompareIteratorByHash> setEntries;
const setEntries & GetMemPoolParents(txiter entry) const;
const setEntries & GetMemPoolChildren(txiter entry) const;
private:
typedef std::map<txiter, setEntries, CompareIteratorByHash> cacheMap;
struct TxLinks {
setEntries parents;
setEntries children;
};
typedef std::map<txiter, TxLinks, CompareIteratorByHash> txlinksMap;
txlinksMap mapLinks;
void UpdateParent(txiter entry, txiter parent, bool add);
void UpdateChild(txiter entry, txiter child, bool add);
std::vector<indexed_transaction_set::const_iterator> GetSortedDepthAndScore() const;
public:
indirectmap<COutPoint, const CTransaction*> mapNextTx;
std::map<uint256, CAmount> mapDeltas;
/** 创建新的mempool
*/
explicit CTxMemPool(CBlockPolicyEstimator* estimator = nullptr);
/**
* 如果开启了sanity-check,那么check函数将会保证pool的一致性,
* 即不包含双花交易,所有的输入都在mapNextTx数组中。
* 如果关闭了sanity-check,那么check函数什么都不做
*/
void check(const CCoinsViewCache *pcoins) const;
void setSanityCheck(double dFrequency = 1.0) { nCheckFrequency = dFrequency * 4294967295.0; }
/**
* addUnchecked函数必须首先更新交易的祖先交易状态,
* 第一个addUnchecked函数可以用来调用CalculateMemPoolAncestors(),
* 然后调用第二个addUnchecked
*/
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, bool validFeeEstimate = true);
bool addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, setEntries &setAncestors, bool validFeeEstimate = true);
void removeRecursive(const CTransaction &tx, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
void removeForReorg(const CCoinsViewCache *pcoins, unsigned int nMemPoolHeight, int flags);
void removeConflicts(const CTransaction &tx);
void removeForBlock(const std::vector<CTransactionRef>& vtx, unsigned int nBlockHeight);
void clear();
void _clear(); //lock free
bool CompareDepthAndScore(const uint256& hasha, const uint256& hashb);
void queryHashes(std::vector<uint256>& vtxid);
bool isSpent(const COutPoint& outpoint);
unsigned int GetTransactionsUpdated() const;
void AddTransactionsUpdated(unsigned int n);
/**
* 检查交易的输入是否在当前的mempool中
*/
bool HasNoInputsOf(const CTransaction& tx) const;
/** 调整 CreateNewBlock 时交易的优先级 */
void PrioritiseTransaction(const uint256& hash, const CAmount& nFeeDelta);
void ApplyDelta(const uint256 hash, CAmount &nFeeDelta) const;
void ClearPrioritisation(const uint256 hash);
public:
/**
*
从mempool中移除一个交易集合,
*
如果一个交易在这个集合中,那么它的所有子孙交易都必须在集合中,
*
除非该交易已经被打包到区块中。
*
如果要移除一个已经被打包到区块中的交易,
*
那么要把updateDescendants设为true,
*
从而更新mempool中所有子孙节点的祖先信息
*/
void RemoveStaged(setEntries &stage, bool updateDescendants, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
/**
*
从竞争失败的Block中更新交易信息到mempool
*/
void UpdateTransactionsFromBlock(const std::vector<uint256> &vHashesToUpdate);
/** 计算mempool中所有entry的祖先
*
limitAncestorCount = 最大祖先数量
*
limitAncestorSize = 最大祖先交易大小
*
limitDescendantCount = 任意祖先的最大子孙数量
*
limitDescendantSize = 任意祖先的最大子孙大小
*
errString = 超过了任何limit限制的错误提示
*
fSearchForParents = 是否在mempool中搜索交易的输入,
*
或者从mapLinks中查找,对于不在mempool中的entry必须设为true
*/
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents = true) const;
/** Populate setDescendants with all in-mempool descendants of hash.
*
Assumes that setDescendants includes all in-mempool descendants of anything
*
already in it.
*/
void CalculateDescendants(txiter it, setEntries &setDescendants);
/**
*
返回进入mempool需要的最小交易费,
*
incrementalRelayFee变量用来限制feerate降到0所需的时间。
*/
CFeeRate GetMinFee(size_t sizelimit) const;
/**
*
移除所有动态大小超过sizelimit的交易,
*
如果传入了pvNoSpendsRemaining,那么将返回不在mempool中并且也没有
*
任何输出在mempool的交易列表
*/
void TrimToSize(size_t sizelimit, std::vector<COutPoint>* pvNoSpendsRemaining=nullptr);
/**
* 移除所有在time之前的交易和它的子孙交易,
* 返回移除的数量
*/
int Expire(int64_t time);
/** 如果交易不满足chain limit,返回false*/
bool TransactionWithinChainLimit(const uint256& txid, size_t chainLimit) const;
unsigned long size()
{
LOCK(cs);
return mapTx.size();
}
uint64_t GetTotalTxSize() const
{
LOCK(cs);
return totalTxSize;
}
bool exists(uint256 hash) const
{
LOCK(cs);
return (mapTx.count(hash) != 0);
}
CTransactionRef get(const uint256& hash) const;
TxMempoolInfo info(const uint256& hash) const;
std::vector<TxMempoolInfo> infoAll() const;
size_t DynamicMemoryUsage() const;
boost::signals2::signal<void (CTransactionRef)> NotifyEntryAdded;
boost::signals2::signal<void (CTransactionRef, MemPoolRemovalReason)> NotifyEntryRemoved;
private:
/** UpdateForDescendants 是被 UpdateTransactionsFromBlock 调用,
* 用来更新被加入pool中的单个交易的子孙节节点;
* setExclude 是内存池中不用更新的子孙交易集合 (because any descendants in
*
setExclude were added to the mempool after the transaction being
*
updated and hence their state is already reflected in the parent
*
state).
*
*
当子孙交易被更新时,cachedDescendants也同时更新
*/
void UpdateForDescendants(txiter updateIt,
cacheMap &cachedDescendants,
const std::set<uint256> &setExclude);
/** Update ancestors of hash to add/remove it as a descendant transaction. */
void UpdateAncestorsOf(bool add, txiter hash, setEntries &setAncestors);
/** 设置一个entry的祖先 */
void UpdateEntryForAncestors(txiter it, const setEntries &setAncestors);
/** 对于每一个要移除的交易,更新它的祖先和直接的儿子。
* 如果updateDescendants 设为 true, 那么还同时更新mempool中子孙的祖先状态
*/
void UpdateForRemoveFromMempool(const setEntries &entriesToRemove, bool updateDescendants);
/** Sever link between specified transaction and direct children. */
void UpdateChildrenForRemoval(txiter entry);
/** 对于一个特定的交易,调用 removeUnchecked 之前,
* 必须为同时为要移除的交易集合调用UpdateForRemoveFromMempool。
*
我们使用每个CTxMemPoolEntry中的setMemPoolParents来遍历
*
要移除交易的祖先,这样能保证我们更新的正确性。
*/
void removeUnchecked(txiter entry, MemPoolRemovalReason reason = MemPoolRemovalReason::UNKNOWN);
};
除了加密货币金融交易之外,许多老手都知道,DeFi 世界里还有一个币圈独家玩法,那就是「挖矿」。挖矿通常能获得不错的收益,因为它的本质是由使用者提供平台流动性,平台进而给予奖励。那么,如何聪明地在 DeFi 世界里到处耕收,而非成为傻傻被收割的韭菜?就必须事先做好功课啦!一池、二池的差异首先,在一个 DeFi 项目中,往往会有一池、二池的设计。一池指的是单币挖矿,也就是俗称的「白嫖池」;而二池则是「LP 池」,为 Liquidity Provider 的缩写,进行的便是众所皆知的流动性挖矿 (Liquidity Mining)。白嫖池:在低风险之下,取得稳定报酬为什么单币挖矿会被称为「白嫖池」,因为使用者只需将手上本来就持有的现货投入矿池质押,即可领取平台方提供的额外奖励,完全是一种「不赚白不赚」的概念!而运作形式通常分两种,第一种是使用稳定币挖矿,质押 USDT、USDC、DAI 等稳定币,挖稳定币或新的项目代币作为奖励;就算挖到的项目代币数量减少,或价值下跌,至少都还是保有本金,这也是风险最低的挖矿方式。第二种的年化报酬率也会比稳定币挖矿更高一点,使用从一池挖出来的项目代币(以下代称 A 币)再挖矿,质押 A 币获得 A 币,或质押 A 币获得其他新币种(以下代称 B 币)。无论是哪种情况,都只需考虑 A 币价格下跌的风险,而因为挖到的 B 币数量会持续增加。整理几种常见单币挖矿的运作形式:1. 质押稳定币,领取稳定币2. 质押稳定币,领取项目代币3. 质押项目代币,领取项目代币4. 质押项目代币,领取其他新币5. 当一个全新 DeFi 项目上线时,白嫖池就是最佳的宣传手段!因为不用承担太多风险,即可获得惊人的年化报酬,肯定会吸引许多 DeFi 玩家蜂拥而至。不过,想维持新项目代币的价格,就要靠项目的真本事了。6. 在新项目取得获得社群信任之前,多数资深玩家只想把握上线前几天的高报酬率(因为通常过两三天至一周左右,矿池的报酬率就会大幅下降),同时也担心几天后的币价崩跌,所以一旦挖到新币就会立刻卖出,以确保一定获利,这就是所谓的「挖提卖」,新项目代币的币价往往维持不易。7. 然而,若是获得社群信任、公认有潜力的项目,比起在第一时间争相卖出,农夫们更会因为看好未来币价走势,而选择持有项目代币。举例来说,像 BSC 上的项目 PancakeSwap,其项目代币 CAKE 走势一路向上,社群的持币意愿增加,就会选择持有现货,或将 CAKE 继续投入其他的矿池。LP 池:提供项目流动性,获得优渥年化收益接下来要介绍二池,也就是俗称的「LP 池」。在 DeFi 项目上线时,初始的 LP 池内就会有两种以上的代币组合,而用户在质押时,也必须提供一定比例的指定代币组合,不能选择只质押单币。虽然流动性挖矿的年化报酬率,比单币挖矿高出许多,但也伴随着风险的提升,其中特别需要留意的,就是「无常损失 (Impermanent Loss)」。项目代币有涨有跌,代币之间的相对价值也会随时改变,身为一个流动性提供者,在提供流动性后,最终领取的资产比例可能与初始组合不同,造成提领时的价值可能不如原先组合的价值。不过,多半流动性挖矿赔钱的主因还是项目代币的币价下跌,因此农夫们还是乐意承担少量的无常损失,提供流动性到各大 DeFi 平台。而现在网络上也有许多无常损失计算器,让大家在投入挖矿之前先做评估。相信大家在看完本文后,会觉得「挖矿」真的是 DeFi 机制其中一个很精彩的设计——白嫖池可以增加项目的流动性,LP 池则能够鼓励新项目代币的锁仓。然而,随着 DeFi 蓬勃发展,不同项目的挖矿规则也日渐复杂。举例来说,Uniswap V3 就提出了新玩法,透过设定价格区间挂单,再给予成交的买卖单挖矿奖励,这就不属于一池、二池的范畴了。了解更多NEWFI资讯 联系社区:new11324

我要回帖

更多关于 股票资金池是什么意思 的文章

 

随机推荐