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

[WIP] One more code checking during the block validation if the previous code checking was failed. #3328

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ namespace AElf.Kernel.CodeCheck.Application;
internal class CodeCheckValidationProvider : IBlockValidationProvider
{
private readonly ICheckedCodeHashProvider _checkedCodeHashProvider;
private readonly ICodeCheckService _codeCheckService;
private readonly IContractReaderFactory<ACS0Container.ACS0Stub> _contractReaderFactory;
private readonly ISmartContractAddressService _smartContractAddressService;

public CodeCheckValidationProvider(ISmartContractAddressService smartContractAddressService,
IContractReaderFactory<ACS0Container.ACS0Stub> contractReaderFactory,
ICheckedCodeHashProvider checkedCodeHashProvider,
ICodeCheckService codeCheckService,
IOptionsSnapshot<CodeCheckOptions> codeCheckOptions)
{
_smartContractAddressService = smartContractAddressService;
_contractReaderFactory = contractReaderFactory;
_checkedCodeHashProvider = checkedCodeHashProvider;
_codeCheckService = codeCheckService;

Logger = NullLogger<CodeCheckValidationProvider>.Instance;
}
Expand Down Expand Up @@ -60,10 +63,29 @@ public async Task<bool> ValidateBlockAfterExecuteAsync(IBlock block)
}

Logger.LogInformation("block hash: {Block}", block);
return codeHashList.Value.All(codeHash => _checkedCodeHashProvider.IsCodeHashExists(new BlockIndex
var contractsFailedCodeCheck = codeHashList.Value.Where(codeHash => !_checkedCodeHashProvider.IsCodeHashExists(
new BlockIndex
{
BlockHash = blockHash,
BlockHeight = block.Header.Height
}, codeHash)).ToList();
if (!contractsFailedCodeCheck.Any()) return true;
foreach (var eventData in contractsFailedCodeCheck.Select(contractFailedCodeCheck =>
{
// TODO: Get contract deploy info.
return new CodeCheckRequired();
}))
{
BlockHash = blockHash,
BlockHeight = block.Header.Height
}, codeHash));
var codeCheckResult = await _codeCheckService.PerformCodeCheckAsync(
eventData.Code.ToByteArray(),
blockHash, block.Header.Height, eventData.Category,
eventData.IsSystemContract);
if (codeCheckResult == false)
{
return false;
}
}

return true;
}
}