-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fork create and token redeem #572
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CService::NotifyBlockChainUpdate是维护mapForkStatus的状态,原来只有新增,这里要考虑下回滚的问题,否则rpc的listfork等操作会有异常
src/bigbang/blockchain.h
Outdated
|
||
protected: | ||
boost::shared_mutex rwAccess; | ||
ICoreProtocol* pCoreProtocol; | ||
ITxPool* pTxPool; | ||
IForkManager* pForkManager; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forkmanager和blockchainxia相互引用,有循环调用或者死锁的隐患
src/bigbang/forkmanager.cpp
Outdated
if (it != mapForkSched.end() && !it->second.IsAllowed()) | ||
{ | ||
vDeactive.push_back(update.hashFork); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里要判断it->second.IsJointEmpty()
src/bigbang/core.cpp
Outdated
uint256 hashNewFork = block.GetHash(); | ||
CTemplatePtr templFork = CTemplate::CreateTemplatePtr(new CTemplateFork(profile.destOwner, hashNewFork)); | ||
if (templFork == nullptr || templFork->GetTemplateId() != tx.sendTo.GetTemplateId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fork的owner和fork template的redeem可以不是同一个
{ | ||
uint256 hashFork; | ||
int nHeight; | ||
if (!pBlockChain->GetTxLocation(tx.vInput[i].prevout.hash, hashFork, nHeight)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core里使用blockchain对象也有死锁的隐患
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
赎回的前序可能是前一个赎回的找零,这种情况不适用“fork交易和赎回在同一个块”的规则。lockedCoin不应该是CTemplateFork::CreatedCoin()
src/storage/blockbase.cpp
Outdated
@@ -451,6 +451,14 @@ bool CBlockBase::Initiate(const uint256& hashGenesis, const CBlock& blockGenesis | |||
return false; | |||
} | |||
|
|||
map<uint256, int> mapValidFork; | |||
mapValidFork.insert(make_pair(hashGenesis, 0)); | |||
if (!dbBlock.AddValidForkHash(hashGenesis, uint256(), mapValidFork)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里处理了创世块,AddNewBlock处理了新增块,原有块的数据没有处理,可能会导致forkmanager那边的判断有问题
src/bigbang/core.cpp
Outdated
if (destIn.GetTemplateId().GetType() == TEMPLATE_FORK) | ||
{ | ||
// TODO: No redemption temporarily | ||
return DEBUG(ERR_TRANSACTION_INVALID, "invalid locked coin template destination\n"); | ||
// CTemplatePtr ptr = CTemplate::CreateTemplatePtr(destIn.GetTemplateId(), vchSig); | ||
// if (!ptr) | ||
// { | ||
// return DEBUG(ERR_TRANSACTION_SIGNATURE_INVALID, "invalid locked coin template destination\n"); | ||
// } | ||
// int64 nLockedCoin = boost::dynamic_pointer_cast<CLockedCoinTemplate>(ptr)->LockedCoin(tx.sendTo, nForkHeight); | ||
// if (nValueIn < tx.nAmount + tx.nTxFee + nLockedCoin) | ||
// { | ||
// return DEBUG(ERR_TRANSACTION_INPUT_INVALID, "valuein is not enough to locked coin (%ld : %ld)\n", nValueIn, tx.nAmount + tx.nTxFee + nLockedCoin); | ||
// } | ||
if (fork != GetGenesisBlockHash()) | ||
{ | ||
return DEBUG(ERR_TRANSACTION_INVALID, "invalid fork"); | ||
} | ||
if (tx.sendTo != destIn) | ||
{ | ||
CTemplatePtr ptr = CTemplate::CreateTemplatePtr(destIn.GetTemplateId(), vchSig); | ||
if (!ptr) | ||
{ | ||
return DEBUG(ERR_TRANSACTION_SIGNATURE_INVALID, "invalid locked coin template destination"); | ||
} | ||
CDestination destRedeemLocked; | ||
uint256 hashForkLocked; | ||
boost::dynamic_pointer_cast<CLockedCoinTemplate>(ptr)->GetForkParam(destRedeemLocked, hashForkLocked); | ||
int64 nLockedCoin = pForkManager->ForkLockedCoin(hashForkLocked, pIndexPrev->GetBlockHash()); | ||
if (nValueIn < tx.nAmount + tx.nTxFee + nLockedCoin) | ||
{ | ||
return DEBUG(ERR_TRANSACTION_INPUT_INVALID, "valuein is not enough to locked coin (%ld : %ld)", nValueIn, tx.nAmount + tx.nTxFee + nLockedCoin); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的校验比VerifyTransaction里面的校验少
do | ||
{ | ||
CForkContext ctxtParent; | ||
if (!cntrBlock.RetrieveForkContext(profile.hashParent, ctxtParent)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
创建这个fork的tx和创建其parent fork的tx可能在同一个块中,因为fork可以接在其parent的origin块后面
} | ||
hashRefFdBlock = fd.hashRefFdBlock; | ||
mapValidFork.clear(); | ||
mapValidFork.insert(fd.mapForkId.begin(), fd.mapForkId.end()); | ||
return true; | ||
} | ||
|
||
void CForkManager::ForkUpdate(const CBlockChainUpdate& update, vector<uint256>& vActive, vector<uint256>& vDeactive) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数还应该有对update.vBlockRemove的同步,将被回滚的fork及其子孙fork放入到vDeactive里
bool fCheckPointBlock, uint256& hashRefFdBlock, map<uint256, int>& mapValidFork) | ||
{ | ||
CValidFdForkId& fd = mapBlockValidFork[hashNewBlock]; | ||
if (fCheckPointBlock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在检查点上记录全fork列表,在其后的普通块中记录增量。这个设计减少了fork的重复记录。可是这只对新同步的节点有用,一直跟着最新的节点会绕开这个设计,浪费很多内存和存储。这个可以再考虑考虑怎么对老节点也起效
如果回滚时不处理blockbase的mapfork,会影响CDispatcher::SyncForkHeight,CBlockMaker,CService,这个要看看有没有问题 |
* Update Version 2.0.5 * Update REF_VACANT_HEIGHT=368638
No description provided.