Skip to content
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

Closed
wants to merge 16 commits into from
Closed

Fork create and token redeem #572

wants to merge 16 commits into from

Conversation

cchanm
Copy link
Contributor

@cchanm cchanm commented Jun 29, 2020

No description provided.

Copy link
Collaborator

@sunhantao sunhantao left a 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等操作会有异常


protected:
boost::shared_mutex rwAccess;
ICoreProtocol* pCoreProtocol;
ITxPool* pTxPool;
IForkManager* pForkManager;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forkmanager和blockchainxia相互引用,有循环调用或者死锁的隐患

Comment on lines 310 to 313
if (it != mapForkSched.end() && !it->second.IsAllowed())
{
vDeactive.push_back(update.hashFork);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里要判断it->second.IsJointEmpty()

Comment on lines 434 to 436
uint256 hashNewFork = block.GetHash();
CTemplatePtr templFork = CTemplate::CreateTemplatePtr(new CTemplateFork(profile.destOwner, hashNewFork));
if (templFork == nullptr || templFork->GetTemplateId() != tx.sendTo.GetTemplateId())
Copy link
Collaborator

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

core里使用blockchain对象也有死锁的隐患

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

赎回的前序可能是前一个赎回的找零,这种情况不适用“fork交易和赎回在同一个块”的规则。lockedCoin不应该是CTemplateFork::CreatedCoin()

@@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里处理了创世块,AddNewBlock处理了新增块,原有块的数据没有处理,可能会导致forkmanager那边的判断有问题

Comment on lines 666 to 687
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);
}
}
Copy link
Collaborator

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))
Copy link
Collaborator

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)
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在检查点上记录全fork列表,在其后的普通块中记录增量。这个设计减少了fork的重复记录。可是这只对新同步的节点有用,一直跟着最新的节点会绕开这个设计,浪费很多内存和存储。这个可以再考虑考虑怎么对老节点也起效

@sunhantao
Copy link
Collaborator

如果回滚时不处理blockbase的mapfork,会影响CDispatcher::SyncForkHeight,CBlockMaker,CService,这个要看看有没有问题

@sunhantao sunhantao mentioned this pull request Jun 29, 2020
@cchanm cchanm closed this Dec 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

分支名字唯一功能,可能存在同名分支在不同节点中存在的问题
3 participants