/// <summary> /// Gets an existing coverage map from the specified address or returns null if it does not exist. /// </summary> /// <param name="contractAddress">The address of the contract to provide a coverage map for.</param> public (CoverageMap undeployedMap, CoverageMap deployedMap) Get(Address contractAddress) { // Try to obtain our undeployed code coverage. CoverageMap undeployedResult = null; _coverageMapsUndeployed.TryGetValue(contractAddress, out undeployedResult); // Try to obtain our deployed code coverage. CoverageMap deployedResult = null; _coverageMapsDeployed.TryGetValue(contractAddress, out deployedResult); // And we return it return(undeployedResult, deployedResult); }
public OhlcData GetRange(TimeRange timeRange) { lock (Lock) { Ctx.Status("Requesting in-memory data"); var seriesId = _adapter.SeriesId; if (!CoverageMap.Covers(timeRange)) { return(null); } var r = MemoryCache.Where(x => x.SeriesId == seriesId && x.DateTimeUtc >= timeRange.UtcFrom && x.DateTimeUtc <= timeRange.UtcTo).ToList(); var d = new OhlcData(timeRange.TimeResolution); d.AddRange(r); return(d); } }
public void StoreRange(OhlcData data, TimeRange rangeAttempted) { lock (Lock) { if (data == null) { return; } if (CoverageMap.Found.Covers(rangeAttempted)) { return; } Parallel.ForEach(data, x => x.SeriesId = _adapter.SeriesId); MemoryCache.AddRange(data); CoverageMap.Include(rangeAttempted, data); } }
public void StoreRange(OhlcData data, TimeRange rangeAttempted) { lock (Lock) { if (data == null) { return; } var isInDb = CoverageMap.Found.Covers(rangeAttempted); if (isInDb) { return; } var seriesId = _adapter.SeriesId; var col = PublicContext.I.GetCollection <OhlcEntry>(); data.ForEach(x => x.SeriesId = seriesId); col.Upsert(data); CoverageMap.Include(rangeAttempted, data); } }
public static (Address Address, uint[] InstructionIndexCoverage, int[] JumpIndexes, int[] NonJumpIndexes) ConvertToSolidityCoverageMap(CoverageMap coverageMap, string opcodes) { // We create a new map for instruction index->execution count instead of instruction offset->execution count. We do the same for jumps List <uint> newMap = new List <uint>(); List <int> newJumps = new List <int>(); List <int> newNonJumps = new List <int>(); // Next we'll want to loop for every item in this list to map instruction indexes to offsets. Dictionary <int, int> instructionOffsetToNumber = GetInstructionOffsetToNumberLookup(opcodes); // We'll want to convert our map from using offsets to indexes, so we use a list and add every consecutive instruction to it. for (int i = 0; i < coverageMap.Map.Length; i++) { // If this offset is in our offset to number translation, there's an instruction at this offset, so we add the execution count. if (instructionOffsetToNumber.ContainsKey(i)) { newMap.Add(coverageMap.Map[i]); } } // Next we'll want to update our jumps for (int i = 0; i < coverageMap.JumpOffsets.Length; i++) { // Obtain our jump offset. int offset = coverageMap.JumpOffsets[i]; // Verify there is an instruction number for this if (!instructionOffsetToNumber.ContainsKey(offset)) { throw new ArgumentException("Could not map instruction offset to instruction index for jump indexes."); } // Add our jump instruction index to our list. newJumps.Add(instructionOffsetToNumber[offset]); } // Next we'll want to update our non-jumps for (int i = 0; i < coverageMap.NonJumpOffsets.Length; i++) { // Obtain our jump offset. int offset = coverageMap.NonJumpOffsets[i]; // Verify there is an instruction number for this if (!instructionOffsetToNumber.ContainsKey(offset)) { throw new ArgumentException("Could not map instruction offset to instruction index for non-jump indexes."); } // Add our jump instruction index to our list. newNonJumps.Add(instructionOffsetToNumber[offset]); } // Obtain the result and return it. var result = (coverageMap.ContractAddress, newMap.ToArray(), newJumps.ToArray(), newNonJumps.ToArray()); return(result); }
private void ExecuteInternal(State state, EVMMessage message, Memory <byte> code) { // Set our current state and message State = state; Message = message; // Create a fresh execuction state. ExecutionState = new EVMExecutionState(this); GasState = new EVMGasState(Message.Gas); Code = code; // Record our call's execution start State.Configuration.DebugConfiguration.RecordExecutionStart(this); // We'll want to wrap our actual execution in a try block to catch any internal VM exceptions specifically bool isPrecompile = EVMPrecompiles.IsPrecompileAddress(Message.CodeAddress); bool threwException = false; try { // Check if address is in precompiles. If so, we execute precompile instead of the provided code. if (isPrecompile) { // Execute our precompiled code. EVMPrecompiles.ExecutePrecompile(this, Message.CodeAddress); } else { // Register our code coverage for this contract (if we're not mining). CoverageMap = State.Configuration.CodeCoverage.Register(Message, Code); // Execute until we have an execution result. while (ExecutionState.Result == null) { // Run another instruction. Step(); } } } catch (Exception exception) { // Record our exception. If we're not a precompile, we mark it as being an in-contract-execution exception. State.Configuration.DebugConfiguration.RecordException(exception, true); // If our exception is an evm exception, we set our execution result. if (exception is EVMException) { // An internal VM exception occurred, we'll want to return nothing, burn all the gas, and revert any changes. ExecutionState.Result = new EVMExecutionResult(this, null, 0, false); } else { // If it's any other type of exception, throw it. throw; } threwException = true; } // If we didn't succeed, record an exception indicating we failed and will revert. if (State.Configuration.DebugConfiguration.ThrowExceptionOnFailResult && !ExecutionState.Result.Succeeded && !threwException) { State.Configuration.DebugConfiguration.RecordException(new Exception("Execution returned a failed result. REVERTING..."), true); } // Record our call's execution end State.Configuration.DebugConfiguration.RecordExecutionEnd(this); }