分散ネットワークChristieによるBlockchainの実装

Takahiro Ikki, Shinji Kono 琉球大学

研究目的

Christie

Christieの言語概念

DGM

DGのアノテーション

Christieのコード例

package christie.example.HelloWorld;

import christie.codegear.CodeGearManager;
import christie.codegear.StartCodeGear;

public class StartHelloWorld extends StartCodeGear {

    public StartHelloWorld(CodeGearManager cgm) {
        super(cgm);
    }

    public static void main(String[] args){
        CodeGearManager cgm = createCGM(10000);
        cgm.setup(new HelloWorldCodeGear());
        cgm.getLocalDGM().put("helloWorld","hello");
        cgm.getLocalDGM().put("helloWorld","world");
    }
}

Annottation

TopologyManager

静的Topology

 MetaGear

ブロックチェーンのトランザクション

BlockHeader

 MetaGear

Blockの動作

Transaction

コンセンサスアルゴリズム

Paxos

Paxosの役割ノード

Paxosの役割定義

paxosのアルゴリズム

paxosのアルゴリズム prepare-promise

 MetaGear

paxosのアルゴリズム accept-accepted

 MetaGear

Paxos

Gears OS の構成図

 gears_structure

Context

 gearef

context の定義

/* context define */
struct Context {
    int codeNum; //実行可能な Code Gear の数
    __code (**code) (struct Context*); //実行可能な code Gear のリスト
    void* heapStart; //Data Gear の Allocate用のヒープ
    void* heap;
    long heapLimit;
    int dataNum; //Data Gear の数
    union Data **data; //Data Gear のリスト
};

#Context

enum Code {
    C_cg1,
    C_cg2,
};
enum Data {
    D_dg1,
    D_dg2,
};

Data Gear の定義

union Data {
    struct Time {
        enum Code next;
        double time;
    } time;
    struct LoopCounter {
        int i;
    } loopCounter;
    ...
};

Interface

Interface のコード

typedef struct Stack<Type, Impl>{
        union Data* stack;
        union Data* data;
        union Data* data1;
        __code whenEmpty(...);
        __code clear(Impl* stack,__code next(...));
        __code push(Impl* stack,Type* data, __code next(...));
        __code pop(Impl* stack, __code next(Type* data, ...));
        __code pop2(Impl* stack, __code next(Type* data, Type* data1, ...));
        __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...));
        __code get(Impl* stack, __code next(Type* data, ...));
        __code get2(Impl* stack, __code next(Type* data, Type* data1, ...));
        __code next(...);
} Stack;

Interface の実装例

Stack* createSingleLinkedStack(struct Context* context) {
    struct Stack* stack = new Stack();
    struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
    stack->stack = (union Data*)singleLinkedStack;
    singleLinkedStack->top = NULL;
    stack->push = C_pushSingleLinkedStack;
    stack->pop  = C_popSingleLinkedStack;
    stack->pop2  = C_pop2SingleLinkedStack;
    stack->get  = C_getSingleLinkedStack;
    stack->get2  = C_get2SingleLinkedStack;
    stack->isEmpty = C_isEmptySingleLinkedStack;
    stack->clear = C_clearSingleLinkedStack;
    return stack;
}

Interface の実装例

__code pushSingleLinkedStack(struct SingleLinkedStack* stack,
                                union Data* data, __code next(...)) {
    Element* element = new Element();
    element->next = stack->top;
    element->data = data;
    stack->top = element;
    goto next(...);
}

interface の使用例

__code stackTest1(struct Stack* stack) {
    Node* node = new Node();
    node->color = Red;
    goto stack->push(node, stackTest2);
}

stub Code Gear

stub Code Gear の例

__code clearSingleLinkedStack(struct Context *context,
                    struct SingleLinkedStack* stack,enum Code next) {
    stack->top = NULL;
    goto meta(context, next);
}

__code clearSingleLinkedStack_stub(struct Context* context) {
        SingleLinkedStack* stack =
                (SingleLinkedStack*)GearImpl(context, Stack, stack);
        enum Code next = Gearef(context, Stack)->next;
        goto clearSingleLinkedStack(context, stack, next);
}

Context、stub Code Gear の自動生成

stub Code Gear の生成

生成された stub Code Gear

__code clearSingleLinkedStack(struct Context *context,
                    struct SingleLinkedStack* stack,enum Code next) {
    stack->top = NULL;
    goto meta(context, next);
}

__code clearSingleLinkedStack_stub(struct Context* context) {
        SingleLinkedStack* stack =
                (SingleLinkedStack*)GearImpl(context, Stack, stack);
        enum Code next = Gearef(context, Stack)->next;
        goto clearSingleLinkedStack(context, stack, next);
}

Context の生成

 generate_context3

今後の課題