Skip to content

Commit

Permalink
Enable automatic decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jun 24, 2022
1 parent 0c4a0bd commit 3aead9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
Expand All @@ -23,7 +24,7 @@ protected override async Task<IEnumerable<JsonElement>> GetEndorsingRights(Block
{
Logger.LogInformation("Trying to load by cycle with 30 minutes timeout...");
#region try aggressive
using var client = new HttpClient
using var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip })
{
BaseAddress = new Uri(Proto.Node.BaseUrl),
Timeout = Timeout.InfiniteTimeSpan
Expand All @@ -43,7 +44,7 @@ protected override async Task<IEnumerable<JsonElement>> GetEndorsingRights(Block
{
Logger.LogInformation("Failed to load by cycle. Loading by level for {0} blocks with 10 seconds timeout...", block.Protocol.BlocksPerCycle);
#region throttle
using var client = new HttpClient
using var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip })
{
BaseAddress = new Uri(Proto.Node.BaseUrl),
Timeout = Timeout.InfiniteTimeSpan
Expand Down
6 changes: 4 additions & 2 deletions Tzkt.Sync/Protocols/Handlers/Proto12/Commits/CycleCommit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public virtual async Task Apply(Block block)
if (!block.Events.HasFlag(BlockEvents.CycleBegin))
return;

var futureCycle = block.Cycle + block.Protocol.PreservedCycles;
var futureCycle = block.Cycle + block.Protocol.PreservedCycles;

var lastSeed = await Db.Cycles
.AsNoTracking()
Expand All @@ -39,12 +39,14 @@ public virtual async Task Apply(Block block)
var futureSeed = Seed.GetNextSeed(lastSeed, nonces);
var snapshotIndex = 0;
var snapshotLevel = 1;
var activation = false;

if (block.Cycle >= 1)
{
if (block.Cycle == block.Protocol.FirstCycle)
{
snapshotLevel = block.Protocol.FirstLevel - 1;
activation = true;
}
else if (block.Cycle == block.Protocol.FirstCycle + 1 && block.Protocol.FirstLevel >= block.Protocol.FirstCycleLevel)
{
Expand All @@ -65,7 +67,7 @@ public virtual async Task Apply(Block block)
.Where(x => x.Level == snapshotLevel && x.DelegateId == null)
.ToListAsync();

var endorsingRewards = await Db.BakerCycles
var endorsingRewards = activation ? new() : await Db.BakerCycles
.AsNoTracking()
.Where(x => x.Cycle == block.Cycle - 1 && x.EndorsementRewards > 0)
.ToDictionaryAsync(x => x.BakerId, x => x.EndorsementRewards);
Expand Down
3 changes: 2 additions & 1 deletion Tzkt.Sync/Utils/TzktClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
Expand All @@ -25,7 +26,7 @@ HttpClient HttpClient
if (DateTime.UtcNow > _Expiration)
{
_HttpClient?.Dispose();
_HttpClient = new HttpClient();
_HttpClient = new(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip });

_HttpClient.BaseAddress = BaseAddress;
_HttpClient.DefaultRequestHeaders.Accept.Add(
Expand Down

0 comments on commit 3aead9e

Please sign in to comment.