Skip to content
Merged

Develop #4010

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
fff01f3
Updates chifra abis with --listItems
tjayrush May 25, 2025
c519f80
Adds chifra abis --list_funcs and --list_events
tjayrush May 29, 2025
10a0773
Expands chifra abis --list_events and --list_funcs
tjayrush May 30, 2025
2b065d4
Adds chifra abis --list --details
tjayrush May 30, 2025
73bbcb2
Adds chifra abis --details
tjayrush May 30, 2025
e356130
Fixes sorting
tjayrush Jun 3, 2025
fc4db8f
Fixes sorting
tjayrush Jun 3, 2025
98ec431
chore: fix function name in comment
gcmutator Jun 6, 2025
2449a10
Fixes issue with articulation
tjayrush Jun 9, 2025
06813af
Merge branch 'develop' into post-530-followon
tjayrush Jun 9, 2025
c68d940
Merge pull request #3998 from gcmutator/develop
tjayrush Jun 9, 2025
c44b043
Merge branch 'develop' into post-530-followon
tjayrush Jun 9, 2025
600d508
Enhanced sorting
tjayrush Jun 10, 2025
0ed2693
Enhanced sorting
tjayrush Jun 10, 2025
47e1ad7
chore: fix some typos in comment
overallteach Jun 11, 2025
ee0e7db
Adds baddresses to chifra names --all
tjayrush Jun 12, 2025
541217b
Adds chifra names --count
tjayrush Jun 13, 2025
110df94
Fix in-memory balance cache key collision between chains
wakamex Jun 16, 2025
e7f5af0
Add test demonstrating cache key collision fix
wakamex Jun 16, 2025
c1591ba
Fixes compilation error in test
tjayrush Jun 17, 2025
de065b8
Merge pull request #4002 from TrueBlocks/wakamex-fix/state-cache-chai…
tjayrush Jun 17, 2025
b3dcb4c
Merge branch 'develop' into post-530-followon
tjayrush Jun 17, 2025
000e80b
Merge branch 'develop' of github.com:overallteach/trueblocks-core int…
tjayrush Jun 17, 2025
2e861e5
Merge branch 'develop' into post-530-followon
tjayrush Jun 17, 2025
f060874
Fix token decimal handling in ToFloatString (fixes #3915)
wakamex Jun 17, 2025
c27e18c
Updates khedra book
tjayrush Jun 18, 2025
189ed2d
Updates tests
tjayrush Jun 18, 2025
91d5e0d
Merge pull request #4004 from TrueBlocks/wakamex-fix/token-decimal-ha…
tjayrush Jun 18, 2025
c747e8e
Merge branch 'develop' into post-530-followon
tjayrush Jun 18, 2025
05ca3c4
Fixes ExportBalances
tjayrush Jun 19, 2025
487659b
chore: fix some typos in comment
yingshanghuangqiao Jun 20, 2025
07487a0
Updates goMaker
tjayrush Jun 20, 2025
4f5557f
Fix #3974: Add chain-specific block time support
wakamex Jun 22, 2025
b560f5e
Fix gofmt formatting issue
wakamex Jun 22, 2025
35da1b4
Fix test expectation for block time calculation
wakamex Jun 22, 2025
db281cf
Cleanings
tjayrush Jun 23, 2025
6e80669
Cleaning
tjayrush Jun 23, 2025
ab0bddc
Fixes problem with --count options for exports, slurps, init, and list
tjayrush Jun 24, 2025
b1e20da
Update
tjayrush Jun 25, 2025
3892328
Adds names of about 150 DOAs. Fixed chifra names --tags
tjayrush Jun 28, 2025
5b5594d
Updates sdk and goMaker
tjayrush Jul 3, 2025
e807d8a
Adds --chains and --caches to chifra status
tjayrush Jul 4, 2025
7e36d71
Fixes for app
tjayrush Jul 4, 2025
f5df25a
Adds support for formatting .tsx aut-gen files
tjayrush Jul 6, 2025
db1dcbb
Cleans names a lot
tjayrush Jul 7, 2025
e9df161
Adds Contract type to core
tjayrush Jul 13, 2025
84219d8
Adds sorting for Contract
tjayrush Jul 14, 2025
dc2de0c
Mocks contracts
tjayrush Jul 14, 2025
a4c8315
Working on removing mocks for Contracts
tjayrush Jul 15, 2025
4954265
Adds an as yet unused EXISTING_CODE block to options.go
tjayrush Jul 17, 2025
d301e41
Cleans up cache auto-code-gen - adds by_address cache type - unused
tjayrush Jul 17, 2025
aac267b
Tries to fix test harness
tjayrush Jul 17, 2025
cea297d
Fixes various tests including acctExport since better caching
tjayrush Jul 17, 2025
41317d5
Removes TestLog from store to ease transaction to modern ABI cache
tjayrush Jul 17, 2025
98c8751
Fixes tests (I hope)
tjayrush Jul 17, 2025
b23ccb8
Fixes tests
tjayrush Jul 17, 2025
c457cb1
Cleans up stateMutability on known ABIs and elsewhere
tjayrush Jul 17, 2025
5fc179e
Prepares for but does not yet enable native caching for Abis
tjayrush Jul 17, 2025
6f5cf4f
Consolidation of abis cache path before switching to native cache
tjayrush Jul 17, 2025
8309f34
Preparing for moving abis to native binary cache
tjayrush Jul 18, 2025
b764fb8
Moves abis cache to v1 but doesn't enable binary
tjayrush Jul 18, 2025
0cac416
Changes file type to .bin
tjayrush Jul 18, 2025
8d0f6b9
Cleans tests
tjayrush Jul 18, 2025
56c44bc
Cleanings
tjayrush Jul 18, 2025
5ca8309
Cleans up lints
tjayrush Jul 18, 2025
962a105
Cleans up ci
tjayrush Jul 18, 2025
b4b19dc
Fixing tests
tjayrush Jul 18, 2025
a2017ad
Merge pull request #4005 from yingshanghuangqiao/master
tjayrush Jul 18, 2025
fd72f46
Back to json abis for a minute
tjayrush Jul 18, 2025
ef3c25d
Enables caches for abis commands
tjayrush Jul 18, 2025
653df91
Enables caches for abis commands
tjayrush Jul 18, 2025
1e26a72
Merge branch 'fix/issue-3974-chain-specific-block-times' of github.co…
tjayrush Jul 18, 2025
feb30c2
Merge branch 'wakamex-fix/issue-3974-chain-specific-block-times' into…
tjayrush Jul 18, 2025
96c9a8b
Better contracts in SDK
tjayrush Jul 18, 2025
d843ebb
Updates go.mods
tjayrush Jul 19, 2025
884f1ed
chore: remove redundant words
pingshuijie Jul 22, 2025
2eb2538
General cleaning and updates READMEs
tjayrush Jul 23, 2025
e8e0006
Changes to fileSize for chunksBloom and chunksIndex
tjayrush Jul 23, 2025
48d9cd1
Changes to fileSize for chunksBloom and chunksIndex
tjayrush Jul 23, 2025
f8b8eef
Adds DryRun and MetaData to chifra chunks
tjayrush Jul 23, 2025
a367d4e
Adds better docs for services
tjayrush Jul 23, 2025
4f93f5b
Cleans up LoadManifest
tjayrush Jul 23, 2025
5bf0ecd
Final cleaning
tjayrush Jul 23, 2025
279fc30
Changes chifra when --timestamps --check --deep N to an int
tjayrush Jul 23, 2025
d389028
Merge branch 'post-530-followon' into pingshuijie-develop
tjayrush Jul 23, 2025
9cca622
Merge pull request #4007 from pingshuijie/develop
tjayrush Jul 23, 2025
d885ee3
Catching up to examples
tjayrush Jul 23, 2025
0a1a8e8
Merge branch 'develop' into post-530-followon
tjayrush Jul 23, 2025
c52a209
Coming soon
tjayrush Jul 23, 2025
c419f1b
Merge branch 'develop' into post-530-followon
tjayrush Jul 23, 2025
48b8d57
Improves chifra when --timestamps --check --deep
tjayrush Jul 23, 2025
e9be0b4
Adds test_khedra.sh
tjayrush Aug 7, 2025
a4cbcbb
Update khedra, sdk, and pinning
tjayrush Aug 7, 2025
9748b58
Fixes crash in ToTransfer function
tjayrush Aug 8, 2025
f42cb63
Rename 'crud' to 'action' for apps
tjayrush Aug 13, 2025
9f720ea
Updates goMaker
tjayrush Aug 14, 2025
f1e7f77
Allows for adding extra routes to the Control Service
tjayrush Aug 17, 2025
234ccc0
Improves a bunch of testing in khedra
tjayrush Aug 17, 2025
5828f93
Small cleanings
tjayrush Aug 17, 2025
b2597e2
Best version yet
tjayrush Aug 19, 2025
f2951c2
Adds Restart to all SDK services and README and cleans up khedra
tjayrush Aug 19, 2025
feab54e
Time based reporting for scraper instead of block count
tjayrush Aug 19, 2025
f969d31
Renames .html.tmpl to .html for syntax highlighting
tjayrush Aug 19, 2025
14adadd
Updates khedra book
tjayrush Aug 19, 2025
1ea4cda
Separates accessibility from enablement for mainnet - fixes bug
tjayrush Aug 21, 2025
cdfa4f7
Updates goMaker
tjayrush Aug 29, 2025
4806ecc
Cleanings in GoMaker
tjayrush Sep 6, 2025
efd2b14
Cleans up use of logger.Fatal and logger.Panic in examples
tjayrush Sep 7, 2025
dd51b4b
Cleans up use of logger.Fatal and logger.Panic for sdk
tjayrush Sep 7, 2025
ce66b4d
Tries to capture proper Fatal/Panic usage in khedra
tjayrush Sep 7, 2025
766fd0a
Tries to clean up Fatal/Panic in dev tools
tjayrush Sep 7, 2025
f3bca93
Cleans up Fatal/Panic in src/apps/pkg/types
tjayrush Sep 7, 2025
a16ed01
Cleans up Fatal/Panic in src/apps/internal which is used by SDK so ca…
tjayrush Sep 7, 2025
f16f4a8
Cleans up Fatal/Panic throughout. We cannot fatal because SDK kills a…
tjayrush Sep 7, 2025
70a23fd
Minor cleanings
tjayrush Sep 7, 2025
03634a2
Improves rpc.PingRpc and removes redundant code from khedra
tjayrush Sep 7, 2025
f2c20f6
Updates go.mods
tjayrush Sep 8, 2025
f675871
Cleaning code-gen
tjayrush Sep 17, 2025
a09e176
Updates sdk
tjayrush Sep 18, 2025
ac36755
Updates tests
tjayrush Sep 23, 2025
e3a19a7
Updates for testing
tjayrush Sep 23, 2025
c450c61
Fixes a ton of lints
tjayrush Sep 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<!-- Please include a summary of the change and which issue is fixed. -->

## PR Target Branch

- [ ] I am targeting the `develop` branch for non-release changes.
100 changes: 100 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# TrueBlocks Core Development Instructions

## Project Overview

TrueBlocks is a Go-based blockchain data indexing system that provides fast, local access to Ethereum transaction data through the "Unchained Index". The project consists of:

- **chifra**: Main CLI tool (`src/apps/chifra/`) built with Cobra framework
- **SDK**: Multi-language bindings (Go, TypeScript, Python) in `sdk/`
- **khedra**: Extension system for specialized indexing (`khedra/`)
- **examples**: Integration examples demonstrating SDK usage (`examples/`)

## Architecture Patterns

**Command Structure**: Each chifra command follows the pattern:
- Command definition in `src/apps/chifra/cmd/[command].go`
- Internal logic in `src/apps/chifra/internal/[command]/`
- Package-specific types in `src/apps/chifra/pkg/types/`

**Data Flow**: RPC → Cache → Index → Output
- RPC calls through `pkg/rpc/`
- Binary cache system in `pkg/cache/`
- Index operations in `pkg/index/`
- Output formatting in `pkg/output/`

**Base Types**: Core blockchain types in `pkg/base/`:
- `base.Address` for Ethereum addresses
- `base.Hash` for transaction/block hashes
- `base.Wei` for precise ETH calculations
- `base.Timestamp` for block times

## Development Workflows

**Building**: Use CMake from `build/` directory or Go directly:
```bash
# Full build with CMake
cd build && make
# Go build only
cd src/apps/chifra && go build
```

**Testing**: Multi-layer approach:
- Unit tests: `go test ./...` in chifra directory
- Integration tests: `scripts/test-all.sh`
- Golden file tests in `tests/gold/`
- Set `TEST_MODE=true` for test-specific behavior

**Code Generation**:
- SDK bindings auto-generated from chifra commands
- Templates in `examples/templates/`
- Use `scripts/go-mod-tidy.sh` for dependency management

## Critical Conventions

**Error Handling**: Always use TrueBlocks patterns:
- `pkg/logger` for logging (not fmt.Print)
- `pkg/validate` for input validation
- Return structured errors, not bare strings

**Configuration**:
- Config files in `~/.local/share/trueblocks/` or `~/Library/Application Support/TrueBlocks/`
- Use `pkg/config` for settings access
- Environment variables prefixed with `TB_`

**Data Structures**:
- Implement `String()` methods for custom types
- Use `pkg/types` for shared data structures
- Follow naming: `Simple[Type]` for basic structs, `[Type]` for full objects

**Multi-Chain Support**:
- Chain-specific configs in config directories
- Use `base.KnownChain` constants
- RPC endpoints configurable per chain

## SDK Integration

**Language Bindings**:
- Go SDK is primary (`sdk/*.go`)
- TypeScript/Python generated from Go definitions
- All SDKs call chifra binary under the hood

**Examples Structure**:
- Each example is self-contained with `go.mod`
- Follow `examples/simple/` pattern for new examples
- Include both programmatic and CLI usage

## Common Pitfalls

- **Don't** use `fmt.Print` - use `pkg/logger`
- **Don't** hardcode chain IDs - use configuration
- **Don't** bypass cache system - use `pkg/cache` for performance
- **Don't** ignore `TEST_MODE` environment variable in test code
- **Always** validate addresses with `base.IsValidAddress()`
- **Always** handle Wei arithmetic with `base.Wei` type

## Key Files to Reference

- `src/apps/chifra/cmd/root.go` - CLI framework setup
- `src/apps/chifra/pkg/base/types.go` - Core type definitions
- `examples/simple/main.go` - Basic SDK usage pattern
- `scripts/test-all.sh` - Complete testing workflow
10 changes: 8 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ jobs:
key: ${{ secrets.SSH_PRIVATE_KEY }}
command_timeout: 40m
script: |
set -e # Exit on any error
rm -rf testing/${{ github.sha }}
mkdir -p testing/${{ github.sha }}
mkdir -p test_results/${{ github.sha }}
Expand All @@ -92,6 +93,11 @@ jobs:
git checkout ${{ github.head_ref }}
git submodule update --init --recursive
cd scripts
CONFIG_FILE=$HOME/trueBlocks.toml bash test-with-docker.sh ${{ github.repository }} ${{ github.sha }} ${{ github.head_ref }}
if CONFIG_FILE=$HOME/trueBlocks.toml bash test-with-docker.sh ${{ github.repository }} ${{ github.sha }} ${{ github.head_ref }}; then
echo "✅ Tests passed successfully"
echo "Results placed in /home/testuser/testing/${{ github.sha }}"
else
echo "❌ Tests failed"
exit 1
fi
docker system prune -af --filter "until=1h"
echo "Results placed in /home/testuser/testing/${{ github.sha }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ py-ext/dist/

node_modules
sdk/typescript/dist
.claude/
118 changes: 65 additions & 53 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,70 @@
# ./.golangci.yml
version: "2"
run:
timeout: 5m
modules-download-mode: readonly

linters:
default: none
enable:
- gofmt # enforces formatting
- revive # custom rules like unused-parameter
- errcheck # unchecked errors
- staticcheck # static analysis
- unused # unused code
- misspell # catches typos
- ineffassign # ineffective assignments
- prealloc # suggests pre-allocation
# - goconst # finds repeated strings for consts
# - gosec # basic security checks
disable-all: true

linters-settings:
gofmt:
simplify: true
revive:
- errcheck
- ineffassign
- misspell
- prealloc
- revive
- staticcheck
- unused
settings:
revive:
rules:
- name: unused-parameter
severity: warning
staticcheck:
checks:
- all
- -QF1008 # could remove embedded field "Xxx" from selector
- -QF1006 # could lift into loop condition
- -ST1003 # should not use MixedCaps in package name
- -ST1016 # methods on the same type should have the same receiver name
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
# - name: var-naming
# severity: warning
- name: unused-parameter
severity: warning
goconst:
min-len: 3 # Minimum length of repeated string
min-occurrences: 3 # Minimum times it must appear
gosec:
excludes:
- G104 # Ignore some noisy security rules (e.g., error handling)

issues:
exclude-rules:
- path: src/apps/chifra/internal/scrape/handle_show.go
linters:
- ineffassign
- path: src/apps/chifra/internal/[^/]+/options\.go
linters:
- ineffassign
- path: src/apps/chifra/pkg/types/types_
linters:
- ineffassign
- path: _test\.go
linters:
- gofmt
- revive
- errcheck
- staticcheck
- unused
- misspell
- goconst
- ineffassign
- prealloc
- gosec
- linters:
- ineffassign
path: src/apps/chifra/internal/scrape/handle_show.go
- linters:
- ineffassign
path: src/apps/chifra/internal/[^/]+/options\.go
- linters:
- ineffassign
path: src/apps/chifra/pkg/types/types_
- linters:
- errcheck
- goconst
- gosec
- ineffassign
- misspell
- prealloc
- revive
- staticcheck
- unused
path: _test\.go
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
settings:
gofmt:
simplify: true
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
- _test\.go
18 changes: 17 additions & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
MD001: false
MD007: false
MD009: false
MD010: false
MD013: false
MD022: false
MD024: false
MD025: false
MD026: false
MD029: false
MD030: false
MD031: false
MD032: false
MD033: false
MD036: false
MD040: false
MD041: false
MD024: false
MD046: false
MD047: false
MD052: false
MD058: false
80 changes: 80 additions & 0 deletions BLOCK_TIME_CONFIG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Block Time Configuration

This document describes the block time configuration system introduced to fix issue #3974 where timestamps on Optimism (and other chains) were incorrect due to hardcoded Ethereum mainnet block times.

## Problem

Previously, TrueBlocks used hardcoded values (13 or 13.3 seconds) for block time calculations across all chains. This caused incorrect timestamp-to-block conversions for chains with different block times like Optimism (2 seconds), Polygon (2 seconds), etc.

## Solution

### 1. Configuration Structure

Added a `blockTime` field to the `ChainGroup` structure in `pkg/configtypes/chain_group.go`:

```go
type ChainGroup struct {
// ... existing fields ...
BlockTime float64 `json:"blockTime" toml:"blockTime,omitempty"`
// ... rest of fields ...
}
```

### 2. Block Time Helper

Created `pkg/config/blocktime.go` with:
- Default block times for known chains
- `GetBlockTime(chain string)` function that:
- First checks configuration file
- Falls back to known defaults
- Uses Ethereum mainnet (13s) as ultimate fallback

### 3. Updated Calculations

Updated hardcoded values in:
- `pkg/tslib/tsdb.go`: Line 100
- `pkg/identifiers/resolve.go`: Line 201

Both now use `config.GetBlockTime(chain)` instead of hardcoded values.

### 4. Configuration

Add block times to your `trueBlocks.toml`:

```toml
[chains.mainnet]
blockTime = 13.0

[chains.optimism]
blockTime = 2.0

[chains.polygon]
blockTime = 2.0
```

## Default Block Times

| Chain | Block Time (seconds) |
|-------|---------------------|
| Ethereum Mainnet | 13.0 |
| Optimism | 2.0 |
| Polygon | 2.0 |
| BSC | 3.0 |
| Gnosis | 5.0 |
| Arbitrum | 0.25 |
| Base | 2.0 |
| Avalanche | 2.0 |
| zkSync Era | 1.0 |

See `pkg/config/blocktime.go` for the complete list.

## Testing

Run tests with:
```bash
go test ./pkg/config/blocktime_test.go
```

## Migration

No action required for existing installations. The system will use defaults if `blockTime` is not configured.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This file details changes made to TrueBlocks over time. All version prior to version 3.0.0 are now no longer supported.

## v6.0.0 - Coming soon...

## v5.0.0 - All About Them Recons - Lancaster (2025/03/28)

**Summary**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Our [official docker version](https://github.com/TrueBlocks/trueblocks-docker) i

## Documentation

The documenation is stored in the ./docs folder of this repo. See our website for the [best available documentation](https://trueblocks.io/).
The documentation is stored in the ./docs folder of this repo. See our website for the [best available documentation](https://trueblocks.io/).

## Linting

Expand Down
Loading
Loading