Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bfa
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Miguel Montes
bfa
Commits
c4e4489e
Commit
c4e4489e
authored
3 years ago
by
Miguel Montes
Browse files
Options
Downloads
Patches
Plain Diff
Corrección de error en detección de URL
parent
86e485cc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/bfa_client/bfa_client.go
+54
-22
54 additions, 22 deletions
cmd/bfa_client/bfa_client.go
with
54 additions
and
22 deletions
cmd/bfa_client/bfa_client.go
+
54
−
22
View file @
c4e4489e
...
...
@@ -76,7 +76,7 @@ func updateURL(url string) (updated string) {
// First, we try IPC
updated
=
defaultIPC
if
bfaNetworkDir
:=
os
.
Getenv
(
"BFANETWORKDIR"
);
bfaNetworkDir
!=
""
{
updated
=
bfaNetworkDir
+
"/node/get.ipc"
updated
=
bfaNetworkDir
+
"/node/get
h
.ipc"
}
if
fileInfo
,
err
:=
os
.
Stat
(
updated
);
err
==
nil
&&
(
fileInfo
.
Mode
()
&
os
.
ModeSocket
)
!=
0
{
return
...
...
@@ -573,16 +573,40 @@ func transfers() {
}
}
type
blockStats
struct
{
BlockNumber
int64
`json:"block_number,omitempty"`
Timestamp
uint64
`json:"timestamp,omitempty"`
}
// Stats collect statistics about a sealer
type
Stats
struct
{
FirstSeen
int64
`json:"first_seen,omitempty"`
LastSeen
int64
`json:"last_seen,omitempty"`
FirstBlockSealed
int64
`json:"first_block_sealed,omitempty"`
LastBlockSealed
int64
`json:"last_block_sealed,omitempty"`
BlocksSealed
int64
`json:"blocks_sealed"`
BlocksAlive
int64
`json:"blocks_alive"`
Availability
float64
`json:"availability"`
recent
bool
FirstSeen
blockStats
`json:"first_seen,omitempty"`
LastSeen
blockStats
`json:"last_seen,omitempty"`
FirstSealed
blockStats
`json:"first_sealed,omitempty"`
LastSealed
blockStats
`json:"last_sealed,omitempty"`
BlocksSealed
int64
`json:"blocks_sealed"`
BlocksAlive
int64
`json:"blocks_alive"`
Availability
float64
`json:"availability"`
recent
bool
}
type
blockTimestamp
struct
{
cache
map
[
int64
]
uint64
node
*
bfa
.
Node
}
func
(
bt
*
blockTimestamp
)
init
(
node
*
bfa
.
Node
)
{
bt
.
cache
=
make
(
map
[
int64
]
uint64
)
bt
.
node
=
node
}
func
(
bt
*
blockTimestamp
)
get
(
blockNumber
int64
)
(
timestamp
uint64
)
{
if
timestamp
,
ok
:=
bt
.
cache
[
blockNumber
];
ok
{
return
timestamp
}
timestamp
=
uint64
(
bt
.
node
.
BlockByNumber
(
blockNumber
)
.
Time
)
bt
.
cache
[
blockNumber
]
=
timestamp
return
}
func
calculateSealerStats
(
url
string
,
first
int64
,
last
int64
,
factor
int64
)
(
sealerStats
map
[
bfa
.
Address
]
*
Stats
)
{
...
...
@@ -633,9 +657,9 @@ func calculateSealerStats(url string, first int64, last int64, factor int64) (se
blocksProcessed
++
if
stats
,
ok
:=
sealerStats
[
sealer
];
ok
{
// We are interested in this sealer
stats
.
Last
Block
Sealed
=
blockNumber
if
stats
.
First
Block
Sealed
==
0
{
stats
.
First
Block
Sealed
=
blockNumber
stats
.
LastSealed
.
BlockNumber
=
blockNumber
if
stats
.
FirstSealed
.
BlockNumber
==
0
{
stats
.
FirstSealed
.
BlockNumber
=
blockNumber
}
stats
.
BlocksSealed
++
stats
.
recent
=
true
...
...
@@ -644,23 +668,23 @@ func calculateSealerStats(url string, first int64, last int64, factor int64) (se
for
sealer
:=
range
snapshot
.
Signers
{
if
stats
,
ok
:=
sealerStats
[
sealer
];
ok
{
// We are only interested if the sealer is in sealersStats
stats
.
LastSeen
=
block
stats
.
LastSeen
.
BlockNumber
=
block
var
firstSeen
bool
if
stats
.
FirstSeen
==
0
{
if
stats
.
FirstSeen
.
BlockNumber
==
0
{
// we have never seen this sealer before
fmt
.
Fprintf
(
os
.
Stderr
,
"Nuevo sellador: %v
\n
"
,
sealer
.
Hex
())
stats
.
FirstSeen
=
block
stats
.
FirstSeen
.
BlockNumber
=
block
firstSeen
=
true
}
if
!
stats
.
recent
{
// sealer is not in snapshot.Recents
if
stats
.
First
Block
Sealed
>
0
{
if
stats
.
FirstSealed
.
BlockNumber
>
0
{
// Sealer has signed at least once, we never zero its BlocksAlive
if
stats
.
Last
Block
Sealed
>
shouldHaveSealedAfter
{
if
stats
.
LastSealed
.
BlockNumber
>
shouldHaveSealedAfter
{
stats
.
BlocksAlive
+=
blocksProcessed
continue
}
}
else
if
stats
.
FirstSeen
<=
shouldHaveSealedAfter
{
}
else
if
stats
.
FirstSeen
.
BlockNumber
<=
shouldHaveSealedAfter
{
// Sealer has never signed since we've seen it for the first time
stats
.
BlocksAlive
=
0
}
else
if
!
firstSeen
{
...
...
@@ -675,8 +699,8 @@ func calculateSealerStats(url string, first int64, last int64, factor int64) (se
stats
.
recent
=
false
// sealer is in snapshot.Recents
if
firstSeen
{
stats
.
FirstSeen
=
stats
.
First
Block
Sealed
stats
.
BlocksAlive
=
block
-
stats
.
FirstSeen
+
1
stats
.
FirstSeen
.
BlockNumber
=
stats
.
FirstSealed
.
BlockNumber
stats
.
BlocksAlive
=
block
-
stats
.
FirstSeen
.
BlockNumber
+
1
}
else
{
stats
.
BlocksAlive
+=
blocksProcessed
}
...
...
@@ -696,10 +720,18 @@ func calculateSealerStats(url string, first int64, last int64, factor int64) (se
}
}
for
_
,
stats
:=
range
sealerStats
{
if
stats
.
LastSeen
==
0
{
bt
:=
blockTimestamp
{}
bt
.
init
(
node
)
if
stats
.
LastSeen
.
BlockNumber
==
0
{
continue
}
blocksSeen
:=
stats
.
LastSeen
-
stats
.
FirstSeen
+
1
stats
.
LastSeen
.
Timestamp
=
bt
.
get
(
stats
.
LastSeen
.
BlockNumber
)
stats
.
FirstSeen
.
Timestamp
=
bt
.
get
(
stats
.
FirstSeen
.
BlockNumber
)
if
stats
.
FirstSealed
.
BlockNumber
>
0
{
stats
.
FirstSealed
.
Timestamp
=
bt
.
get
(
stats
.
FirstSealed
.
BlockNumber
)
stats
.
LastSealed
.
Timestamp
=
bt
.
get
(
stats
.
LastSealed
.
BlockNumber
)
}
blocksSeen
:=
stats
.
LastSeen
.
BlockNumber
-
stats
.
FirstSeen
.
BlockNumber
+
1
stats
.
Availability
=
float64
(
stats
.
BlocksAlive
)
/
float64
(
blocksSeen
)
}
return
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment