Skip to content

Commit

Permalink
Merge pull request #4 from filecoin-project/feat/f2-chain
Browse files Browse the repository at this point in the history
chain: Use f2 code
  • Loading branch information
whyrusleeping authored Jul 8, 2019
2 parents 7cd869d + c69e241 commit 03227e1
Show file tree
Hide file tree
Showing 38 changed files with 5,060 additions and 20 deletions.
126 changes: 120 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,136 @@ orbs:
go: gotest/[email protected]


commands:
install-deps:
steps:
- go/install-ssh
- go/install: {package: git}
- go/install: {package: bzr}
prepare:
steps:
- checkout
- run: git submodule sync
- run: git submodule update --init


jobs:
mod-tidy-check:
executor: go/circleci-golang
steps:
- go/install-ssh
- checkout
- install-deps
- prepare
- go/mod-download
- go/mod-tidy-check

test:
description: |
Run tests with gotestsum.
parameters:
executor:
type: executor
default: go/circleci-golang
go-test-flags:
type: string
default: ""
description: Flags passed to go test.
packages:
type: string
default: "./..."
description: Import paths of packages to be tested.
test-suite-name:
type: string
default: unit
description: Test suite name to report to CircleCI.
gotestsum-format:
type: string
default: short
description: gotestsum format. https://github.com/gotestyourself/gotestsum#format
coverage:
type: string
default: -coverprofile=coverage.txt
description: Coverage flag. Set to the empty string to disable.
codecov-upload:
type: boolean
default: false
description: |
Upload coverage report to https://codecov.io/. Requires the codecov API token to be
set as an environment variable for private projects.
executor: << parameters.executor >>
steps:
- install-deps
- prepare
- go/mod-download
- run: make deps
- go/install-gotestsum:
gobin: $HOME/.local/bin
- run:
name: go test
environment:
GOTESTSUM_JUNITFILE: /tmp/test-reports/<< parameters.test-suite-name >>/junit.xml
GOTESTSUM_FORMAT: << parameters.gotestsum-format >>
command: |
mkdir -p /tmp/test-reports/<< parameters.test-suite-name >>
gotestsum -- \
<< parameters.coverage >> \
<< parameters.go-test-flags >> \
<< parameters.packages >>
- store_test_results:
path: /tmp/test-reports
- when:
condition: << parameters.codecov-upload >>
steps:
- go/install: {package: bash}
- go/install: {package: curl}
- run:
shell: /bin/bash -eo pipefail
command: |
bash <(curl -s https://codecov.io/bash)
lint:
description: |
Run golangci-lint.
parameters:
executor:
type: executor
default: go/circleci-golang
golangci-lint-version:
type: string
default: 1.17.1
concurrency:
type: string
default: '2'
description: |
Concurrency used to run linters. Defaults to 2 because NumCPU is not
aware of container CPU limits.
args:
type: string
default: ''
description: |
Arguments to pass to golangci-lint
executor: << parameters.executor >>
steps:
- install-deps
- prepare
- go/mod-download
- run: make deps
- go/install-golangci-lint:
gobin: $HOME/.local/bin
version: << parameters.golangci-lint-version >>
- run:
name: Lint
command: |
golangci-lint run -v \
--concurrency << parameters.concurrency >> << parameters.args >>
workflows:
version: 2
ci:
jobs:
- go/lint:
golangci-lint-version: 1.17.1
- go/test:
executor: go/circleci-golang
- lint
- lint:
args: "--no-config --exclude-use-default=false --disable-all --enable golint"
- test:
codecov-upload: true
- mod-tidy-check
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
lotus
**/*.h
**/*.a
**/*.pc
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ issues:
exclude:
- "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
- "Potential file inclusion via variable"
- "should have( a package)? comment"

exclude-use-default: false
exclude-rules:
- path: node/modules/lp2p
linters:
- golint
- path: ".*_test.go"
linters:
- gosec

linters-settings:
goconst:
Expand Down
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: build

blssigs: lib/bls-signatures/include/libbls_signatures.h

lib/bls-signatures/include/libbls_signatures.h: lib/bls-signatures/bls-signatures ;
./scripts/install-bls-signatures.sh

deps: blssigs

build: deps
go build -o lotus ./cmd/lotus

.PHONY: all build deps blssigs
4 changes: 2 additions & 2 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package client

import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/rpclib"
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
)

// NewRPC creates a new http jsonrpc client.
func NewRPC(addr string) api.API {
var res api.Struct
rpclib.NewClient(addr, "Filecoin", &res.Internal)
jsonrpc.NewClient(addr, "Filecoin", &res.Internal)
return &res
}
111 changes: 111 additions & 0 deletions chain/actors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package chain

import (
"context"
"fmt"

"github.com/filecoin-project/go-lotus/chain/address"

"github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
cbor "github.com/ipfs/go-ipld-cbor"
mh "github.com/multiformats/go-multihash"
)

func init() {
cbor.RegisterCborType(InitActorState{})
cbor.RegisterCborType(AccountActorState{})
}

var AccountActorCodeCid cid.Cid
var StorageMarketActorCodeCid cid.Cid
var StorageMinerCodeCid cid.Cid
var MultisigActorCodeCid cid.Cid
var InitActorCodeCid cid.Cid

var InitActorAddress = mustIDAddress(0)
var NetworkAddress = mustIDAddress(1)
var StorageMarketAddress = mustIDAddress(2)

func mustIDAddress(i uint64) address.Address {
a, err := address.NewIDAddress(i)
if err != nil {
panic(err)
}
return a
}

func init() {
pref := cid.NewPrefixV1(cid.Raw, mh.ID)
mustSum := func(s string) cid.Cid {
c, err := pref.Sum([]byte(s))
if err != nil {
panic(err)
}
return c
}

AccountActorCodeCid = mustSum("account")
StorageMarketActorCodeCid = mustSum("smarket")
StorageMinerCodeCid = mustSum("sminer")
MultisigActorCodeCid = mustSum("multisig")
InitActorCodeCid = mustSum("init")
}

type VMActor struct {
}

type InitActorState struct {
AddressMap cid.Cid

NextID uint64
}

func (ias *InitActorState) AddActor(vmctx *VMContext, addr address.Address) (address.Address, error) {
nid := ias.NextID
ias.NextID++

amap, err := hamt.LoadNode(context.TODO(), vmctx.Ipld(), ias.AddressMap)
if err != nil {
return address.Undef, err
}

if err := amap.Set(context.TODO(), string(addr.Bytes()), nid); err != nil {
return address.Undef, err
}

if err := amap.Flush(context.TODO()); err != nil {
return address.Undef, err
}

ncid, err := vmctx.Ipld().Put(context.TODO(), amap)
if err != nil {
return address.Undef, err
}
ias.AddressMap = ncid

return address.NewIDAddress(nid)
}

func (ias *InitActorState) Lookup(cst *hamt.CborIpldStore, addr address.Address) (address.Address, error) {
amap, err := hamt.LoadNode(context.TODO(), cst, ias.AddressMap)
if err != nil {
return address.Undef, err
}

val, err := amap.Find(context.TODO(), string(addr.Bytes()))
if err != nil {
return address.Undef, err
}

ival, ok := val.(uint64)
if !ok {
return address.Undef, fmt.Errorf("invalid value in init actor state, expected uint64, got %T", val)
}

return address.NewIDAddress(ival)
}

type AccountActorState struct {
Address address.Address
}
Loading

0 comments on commit 03227e1

Please sign in to comment.